Creating Agents
Agents are the core building blocks of Flo AI. They represent AI-powered entities that can process inputs, use tools, and generate responses.AgentBuilder Methods
TheAgentBuilder class provides a fluent interface for configuring agents. All methods return self for method chaining. Here’s a complete reference:
| Method | Description | Parameters |
|---|---|---|
with_name(name: str) | Set the agent’s name | name: Display name for the agent |
with_prompt(system_prompt: str | AssistantMessage) | Set the system prompt | system_prompt: Instructions defining agent behavior |
with_llm(llm: BaseLLM) | Configure the LLM provider | llm: Instance of OpenAI, Anthropic, Gemini, etc. |
with_tools(tools: List[Tool]) | Add tools to the agent | tools: List of Tool objects, ToolConfig, or tool dicts |
add_tool(tool: Tool, **prefilled_params) | Add a single tool with optional pre-filled parameters | tool: Tool object, **prefilled_params: Parameters to pre-fill |
with_reasoning(pattern: ReasoningPattern) | Set reasoning pattern | pattern: REACT, COT, or DIRECT |
with_retries(max_retries: int) | Set maximum retry attempts | max_retries: Number of retries on failure (default: 3) |
with_output_schema(schema: Dict | Type[BaseModel]) | Set structured output schema | schema: Pydantic model class or JSON schema dict |
with_role(role: str) | Set the agent’s role | role: Internal role description |
with_actas(act_as: str) | Set how agent presents itself | act_as: Message role (e.g., ‘assistant’, ‘user’) |
build() | Create and return the configured Agent | Returns: Agent instance |
with_llm() is required before calling build(). All other methods are optional.
Basic Agent Creation
Create a simple conversational agent:Agent Configuration
Configure agents with various options:Agent Types
Conversational Agents
Basic agents for chat and Q&A:Tool-Using Agents
Agents that can use external tools:Structured Output Agents
Agents that return structured data:Agent Capabilities
Variable Resolution
Use dynamic variables in agent prompts:Document Processing
Process PDF and text documents:Error Handling
Built-in retry mechanisms and error recovery:Conversation History
Agents automatically maintain conversation history across multiple interactions. Therun() method returns the complete conversation history as a list of messages.
Accessing Conversation History
The conversation history is stored in theconversation_history attribute:
Clearing History
Clear the conversation history to start a new conversation:Manual History Management
You can manually add messages to the conversation history:Best Practices
Prompt Engineering
- Be specific: Clearly define the agent’s role and capabilities
- Use examples: Provide examples of expected inputs and outputs
- Set boundaries: Define what the agent should and shouldn’t do
Model Selection
Choose the right model for your use case:- GPT-4o: Best for complex reasoning and analysis
- GPT-4o-mini: Good balance of performance and cost
- Claude-3.5-Sonnet: Excellent for creative tasks
- Gemini: Good for multilingual applications

