Building Blocks
Agent
The Agent
class provides an easy to use interface to language models.
Example
agent.py
Agent Params
Parameter | Type | Default | Description |
---|---|---|---|
model | Optional[Model] | None | Model to use for this Agent (alias: "provider") |
name | Optional[str] | None | Agent name |
agent_id | Optional[str] | None | Agent UUID (autogenerated if not set) |
agent_data | Optional[Dict[str, Any]] | None | Metadata associated with this agent |
introduction | Optional[str] | None | Agent introduction. This is added to the chat history when a run is started. |
user_id | Optional[str] | None | ID of the user interacting with this agent |
user_data | Optional[Dict[str, Any]] | None | Metadata associated with the user interacting with this agent |
session_id | Optional[str] | None | Session UUID (autogenerated if not set) |
session_name | Optional[str] | None | Session name |
session_data | Optional[Dict[str, Any]] | None | Metadata associated with this session |
memory | AgentMemory | AgentMemory() | Agent Memory |
add_history_to_messages | bool | False | Add chat history to the messages sent to the Model. (alias: "add_chat_history_to_messages") |
num_history_responses | int | 3 | Number of historical responses to add to the messages. |
knowledge | Optional[AgentKnowledge] | None | Agent Knowledge (alias: "knowledge_base") |
add_context | bool | False | Enable RAG by adding context from AgentKnowledge to the user prompt. |
retriever | Optional[Callable[..., Optional[list[dict]]]] | None | Function to get context to add to the user_message |
context_format | Literal["json", "yaml"] | "json" | Format of the context |
add_context_instructions | bool | False | If True, add instructions for using the context to the system prompt |
storage | Optional[AgentStorage] | None | Agent Storage |
tools | Optional[List[Union[Tool, Toolkit, Callable, Dict, Function]]] | None | A list of tools provided to the Model. |
show_tool_calls | bool | False | Show tool calls in Agent response. |
tool_call_limit | Optional[int] | None | Maximum number of tool calls allowed. |
tool_choice | Optional[Union[str, Dict[str, Any]]] | None | Controls which (if any) tool is called by the model. |
reasoning | bool | False | Enable reasoning by working through the problem step by step. |
reasoning_model | Optional[Model] | None | Model to use for reasoning |
reasoning_agent | Optional[Agent] | None | Agent to use for reasoning |
reasoning_min_steps | int | 1 | Minimum number of reasoning steps |
reasoning_max_steps | int | 10 | Maximum number of reasoning steps |
read_chat_history | bool | False | Add a tool that allows the Model to read the chat history. |
search_knowledge | bool | True | Add a tool that allows the Model to search the knowledge base (aka Agentic RAG) |
update_knowledge | bool | False | Add a tool that allows the Model to update the knowledge base. |
read_tool_call_history | bool | False | Add a tool that allows the Model to get the tool call history. |
add_messages | Optional[List[Union[Dict, Message]]] | None | A list of extra messages added after the system message and before the user message. |
system_prompt | Optional[str] | None | System prompt: provide the system prompt as a string |
system_prompt_template | Optional[PromptTemplate] | None | System prompt template: provide the system prompt as a PromptTemplate |
use_default_system_message | bool | True | If True, build a default system message using agent settings and use that |
system_message_role | str | "system" | Role for the system message |
description | Optional[str] | None | A description of the Agent that is added to the start of the system message. |
task | Optional[str] | None | The task the agent should achieve. |
instructions | Optional[List[str]] | None | List of instructions for the agent. |
guidelines | Optional[List[str]] | None | List of guidelines for the agent. |
expected_output | Optional[str] | None | Provide the expected output from the Agent. |
additional_context | Optional[str] | None | Additional context added to the end of the system message. |
prevent_hallucinations | bool | False | If True, add instructions to return "I dont know" when the agent does not know the answer. |
prevent_prompt_leakage | bool | False | If True, add instructions to prevent prompt leakage |
limit_tool_access | bool | False | If True, add instructions for limiting tool access to the default system prompt if tools are provided |
markdown | bool | False | If markdown=true, add instructions to format the output using markdown |
add_name_to_instructions | bool | False | If True, add the agent name to the instructions |
add_datetime_to_instructions | bool | False | If True, add the current datetime to the instructions to give the agent a sense of time |
user_prompt | Optional[Union[List, Dict, str]] | None | User prompt: provide the user prompt as a string |
user_prompt_template | Optional[PromptTemplate] | None | User prompt template: provide the user prompt as a PromptTemplate |
use_default_user_message | bool | True | If True, build a default user prompt using references and chat history |
user_message_role | str | "user" | Role for the user message |
response_model | Optional[Type[BaseModel]] | None | Provide a response model to get the response as a Pydantic model (alias: "output_model") |
parse_response | bool | True | If True, the response from the Model is converted into the response_model |
structured_outputs | bool | False | Use the structured_outputs from the Model if available |
save_response_to_file | Optional[str] | None | Save the response to a file |
team | Optional[List["Agent"]] | None | An Agent can have a team of agents that it can transfer tasks to. |
role | Optional[str] | None | When the agent is part of a team, this is the role of the agent in the team |
add_transfer_instructions | bool | True | Add instructions for transferring tasks to team members |
debug_mode | bool | False | debug_mode=True enables debug logs |
monitoring | bool | False | monitoring=True logs Agent information to phidata.app for monitoring |
telemetry | bool | True | telemetry=True logs minimal telemetry for analytics |
Was this page helpful?