agent.mdx


Overview

The Agent component is a core part of the Ragflow framework designed to empower Large Language Models (LLMs) with autonomous reasoning, tool usage, and multi-agent collaboration capabilities. Since version 0.20.5, the Agent can operate independently or as a planner orchestrating tools and subagents, enabling sophisticated workflows involving reflection, adjustment, and task delegation.

The Agent component is primarily responsible for fine-tuning the LLM prompt and managing its interaction with tools and other agents, facilitating complex tasks such as summarization, translation, or multi-step control processes.


Detailed Explanation

Purpose and Functionality


Components of the Agent

This documentation focuses on the Agent component as a configuration and runtime entity within Ragflow. It is not a traditional code file but a component specification guiding the behavior of LLM-driven agents.

Configuration Parameters

Parameter

Description

Default / Notes

Model

Chat model to use for the Agent. Different models can be used per component.

Must be configured via the Model providers page.

Freedom

Preset configuration controlling Temperature, Top P, Presence penalty, and Frequency penalty.

Options: Improvise, Precise (default), Balance

Temperature

Controls randomness/creativity of output. Lower = deterministic, higher = creative.

Default 0.1

Top P

Nucleus sampling threshold to avoid repetitive/unrealistic text.

Default 0.3

Presence penalty

Encourages use of new tokens to increase response diversity.

Default 0.4

Frequency penalty

Discourages repeated tokens for more conservative output.

Default 0.7

Max tokens

Maximum number of tokens to generate in output.

Not explicitly defined in document

System prompt

Defines the LLM's role, behavior, and instructions. Supports advanced prompt blocks including task analysis, planning, reflection, citation guidelines.

Customizable; can override defaults

User prompt

Defines the specific task or query for the model. Defaults to sys.query. In standalone mode, often includes formalized_content from retrieval components.

User-defined

Tools

External utilities the agent can invoke to assist with tasks.

Configurable; optional

Agent

Sub-agents that collaborate with this Agent forming a multi-agent system.

Configurable; optional

Message window size

Number of previous dialogue rounds fed into the LLM for context in multi-turn conversations.

Integer; used only for multi-turn dialogues

Max retries

Maximum number of retry attempts on task failure.

Integer

Delay after error

Seconds to wait before retrying a failed operation.

Default 1 second

Max reflection rounds

Number of reflection cycles the Agent performs to improve reasoning accuracy.

Default 1; higher values increase response time

Output

Global variable name for the Agent's output, accessible by other workflow components.

User-defined


Advanced Prompt Blocks (v0.20.5+)

The Agent supports advanced, framework-level prompt blocks to modularize and customize its reasoning workflow. These blocks can be selected or overridden in the System prompt configuration:

Block Name

Purpose

Input Variables

Usage Scenario

task_analysis

Analyze the current task or delegated sub-task.

agent_prompt, task, tool_desc, context

For planners orchestrating tools or sub-Agents

plan_generation

Generate the next plan or step for the Agent to execute based on task analysis.

task_analysis, desc, today

For planners with sub-Agents/tools

reflection

Reflect on previous actions to improve accuracy and efficiency.

goal, tool_calls (including call.name and call.result)

For planners employing iterative reasoning

citation_guidelines

Provide citation styles or guidelines for output.

None specified

For Agents requiring formatted citations


Usage Examples

Standalone Agent Configuration

Agent as a Planner with MCP Server


Important Implementation Details


Interaction with Other System Components


Frequently Asked Questions

Why does the Agent take a long time to respond?


Best Practices


Visual Diagram: Structure of the Agent Component

classDiagram
    class Agent {
        +model: ChatModel
        +freedom: enum {Improvise, Precise, Balance}
        +temperature: float
        +top_p: float
        +presence_penalty: float
        +frequency_penalty: float
        +max_tokens: int
        +system_prompt: string
        +user_prompt: string
        +tools: List~Tool~
        +sub_agents: List~Agent~
        +message_window_size: int
        +max_retries: int
        +delay_after_error: int
        +max_reflection_rounds: int
        +output_variable: string
        +run()
        +reflect()
        +plan()
        +call_tools()
    }

    class Tool {
        +name: string
        +invoke()
    }

    Agent "1" *-- "*" Tool : uses
    Agent "1" *-- "*" Agent : sub_agents

Summary

The Agent component in Ragflow is a highly configurable LLM orchestrator that supports autonomous reasoning, tool invocation, and multi-agent collaboration. It balances flexibility with usability via intuitive configuration options and advanced prompt engineering features. Its integration with chat models, external tools, and subagents enables powerful workflows for complex AI-driven tasks.

This documentation provides the conceptual and practical details needed to effectively configure and use the Agent component within Ragflow workflows.