Agent Templates Guide¶
Pre-configured agent templates for common use cases. Templates create fully configured agent instances with all necessary resources.
Location: bast_ai_agno.bp.agent_templates
Reference: Agno Agent Documentation
Table of Contents¶
Overview¶
Agent templates are high-level functions that create fully configured agent instances with: - All necessary resources (models, storage, knowledge, memory) - Optimized configurations for specific use cases - Ready-to-use agent instances
Templates vs Configurations vs Presets¶
- Configurations (
dto/agent_configs.py): Dictionary configurations - Presets (
dto/agent_preset_utils.py): Functions that return configuration dictionaries - Templates (
bp/agent_templates.py): Functions that return fully configured Agent instances
When to Use Templates¶
✅ Use templates when: - You want a ready-to-use agent with minimal setup - You need a common pattern (RAG, tools, conversational, reasoning) - You want all resources automatically configured
❌ Don't use templates when: - You need custom resource setup - You want to reuse existing resources - You need fine-grained control over configuration
Quick Start¶
Basic Template Usage¶
from bast_ai_agno.bp.agent_templates import create_rag_agent_template
# Create a RAG agent with all resources
agent = create_rag_agent_template(
cat_name="myapp",
agent_name="my_rag_agent",
knowledge_base_name="my_kb"
)
# Use immediately
response = agent.run(
input="What is the answer?",
user_id="user123",
session_id="session1"
)
Template Types¶
1. RAG Agent Template¶
Creates an agent optimized for knowledge base search.
Function: create_rag_agent_template()
Features: - Knowledge base integration - Automatic knowledge search - Memory capabilities (optional) - RAG-optimized instructions
Parameters:
- cat_name (str): Catalog name for resources
- agent_name (str): Name for the agent
- knowledge_base_name (str, optional): Name of knowledge base (defaults to agent_name)
- model_id (str): Model ID (default: "gpt-4o-mini")
- search_knowledge (bool): Enable knowledge search (default: True)
- enable_memory (bool): Enable memory (default: True)
- custom_instructions (List[str], optional): Custom instructions
Example:
from bast_ai_agno.bp.agent_templates import create_rag_agent_template
agent = create_rag_agent_template(
cat_name="myapp",
agent_name="medical_assistant",
knowledge_base_name="medical_kb",
search_knowledge=True,
enable_memory=True
)
2. Tool-Using Agent Template¶
Creates an agent optimized for external tool integration.
Function: create_tool_agent_template()
Features: - Tool integration - Configurable tool call limits - Tool choice strategies - Tool-optimized instructions
Parameters:
- cat_name (str): Catalog name for resources
- agent_name (str): Name for the agent
- tools (List[Any]): List of tool instances
- model_id (str): Model ID (default: "gpt-4o-mini")
- tool_call_limit (int, optional): Maximum tool calls per run
- tool_choice (str): Tool choice strategy ("auto", "required", "none") (default: "auto")
- enable_memory (bool): Enable memory (default: False)
- custom_instructions (List[str], optional): Custom instructions
Example:
from bast_ai_agno.bp.agent_templates import create_tool_agent_template
from agno.tools.duckduckgo import DuckDuckGoTools
agent = create_tool_agent_template(
cat_name="myapp",
agent_name="research_assistant",
tools=[DuckDuckGoTools(modifier="site:example.com")],
tool_call_limit=10,
tool_choice="auto"
)
3. Conversational Agent Template¶
Creates an agent optimized for multi-turn conversations.
Function: create_conversational_agent_template()
Features: - Session management - Conversation history - Memory capabilities - Session summaries - Conversational-optimized instructions
Parameters:
- cat_name (str): Catalog name for resources
- agent_name (str): Name for the agent
- model_id (str): Model ID (default: "gpt-4o-mini")
- enable_memory (bool): Enable memory (default: True)
- num_history_runs (int): Number of history runs (default: 10)
- enable_session_summaries (bool): Enable session summaries (default: True)
- custom_instructions (List[str], optional): Custom instructions
Example:
from bast_ai_agno.bp.agent_templates import create_conversational_agent_template
agent = create_conversational_agent_template(
cat_name="myapp",
agent_name="chat_assistant",
enable_memory=True,
num_history_runs=15
)
4. Reasoning Agent Template¶
Creates an agent optimized for complex problem solving.
Function: create_reasoning_agent_template()
Features: - Reasoning capabilities - Configurable reasoning steps - Memory capabilities (optional) - Reasoning-optimized instructions
Parameters:
- cat_name (str): Catalog name for resources
- agent_name (str): Name for the agent
- model_id (str): Model ID (default: "gpt-4o-mini")
- min_steps (int): Minimum reasoning steps (default: 2)
- max_steps (int): Maximum reasoning steps (default: 15)
- enable_memory (bool): Enable memory (default: True)
- custom_instructions (List[str], optional): Custom instructions
Example:
from bast_ai_agno.bp.agent_templates import create_reasoning_agent_template
agent = create_reasoning_agent_template(
cat_name="myapp",
agent_name="analyst",
min_steps=3,
max_steps=20
)
Usage Examples¶
Example 1: Simple RAG Agent¶
from bast_ai_agno.bp.agent_templates import create_rag_agent_template
# Create RAG agent
agent = create_rag_agent_template(
cat_name="myapp",
agent_name="doc_assistant",
knowledge_base_name="docs_kb"
)
# Use for queries
response = agent.run(
input="What is the installation process?",
user_id="user123",
session_id="session1"
)
Example 2: Tool-Enabled Research Agent¶
from bast_ai_agno.bp.agent_templates import create_tool_agent_template
from agno.tools.duckduckgo import DuckDuckGoTools
# Create tool agent
agent = create_tool_agent_template(
cat_name="myapp",
agent_name="researcher",
tools=[DuckDuckGoTools()],
tool_call_limit=5
)
# Use for research
response = agent.run(
input="Find the latest developments in quantum computing",
user_id="user123",
session_id="session1"
)
Example 3: Customer Support Agent¶
from bast_ai_agno.bp.agent_templates import create_conversational_agent_template
# Create conversational agent
agent = create_conversational_agent_template(
cat_name="myapp",
agent_name="support_agent",
enable_memory=True,
num_history_runs=20,
enable_session_summaries=True
)
# Use for customer support
response = agent.run(
input="I need help with my account",
user_id="customer123",
session_id="support_ticket_1"
)
Example 4: Analysis Agent with Reasoning¶
from bast_ai_agno.bp.agent_templates import create_reasoning_agent_template
# Create reasoning agent
agent = create_reasoning_agent_template(
cat_name="myapp",
agent_name="analyst",
min_steps=3,
max_steps=15,
enable_memory=True
)
# Use for complex analysis
response = agent.run(
input="Analyze this data and provide insights...",
user_id="analyst123",
session_id="analysis1"
)
Example 5: Custom Instructions¶
from bast_ai_agno.bp.agent_templates import create_rag_agent_template
# Create RAG agent with custom instructions
agent = create_rag_agent_template(
cat_name="myapp",
agent_name="medical_assistant",
knowledge_base_name="medical_kb",
custom_instructions=[
"You are a medical assistant specialized in medication information.",
"Always cite sources from the knowledge base.",
"Provide clear and concise answers.",
"If information is not in the knowledge base, recommend consulting a healthcare professional."
]
)
Best Practices¶
1. Use Templates for Common Patterns¶
# ✅ Good: Use template for common pattern
agent = create_rag_agent_template(
cat_name="myapp",
agent_name="kb_agent",
knowledge_base_name="my_kb"
)
# ❌ Avoid: Manual setup for common patterns
# (unless you need custom resource setup)
2. Customize Instructions When Needed¶
# ✅ Good: Customize instructions for domain-specific needs
agent = create_rag_agent_template(
cat_name="myapp",
agent_name="legal_assistant",
knowledge_base_name="legal_kb",
custom_instructions=[
"You are a legal assistant.",
"Always cite legal sources.",
"Provide disclaimers about legal advice."
]
)
3. Choose Appropriate Template¶
# ✅ RAG: For knowledge base queries
agent = create_rag_agent_template(...)
# ✅ Tools: For external integrations
agent = create_tool_agent_template(...)
# ✅ Conversational: For multi-turn chats
agent = create_conversational_agent_template(...)
# ✅ Reasoning: For complex problems
agent = create_reasoning_agent_template(...)
4. Use Factory for Custom Setups¶
# ✅ Use factory when you need custom resource setup
from bast_ai_agno.bp.agno_agents import AgnoAgentFactory
factory = AgnoAgentFactory("myapp")
# Custom setup with existing resources
agent = factory.create_openai_chat_agent(...)
Comparison: Templates vs Factory vs Configurations¶
Templates (Recommended for Common Patterns)¶
from bast_ai_agno.bp.agent_templates import create_rag_agent_template
agent = create_rag_agent_template(
cat_name="myapp",
agent_name="my_agent",
knowledge_base_name="my_kb"
)
Pros: - ✅ Minimal setup - ✅ All resources configured automatically - ✅ Optimized for specific use cases - ✅ Ready to use immediately
Cons: - ❌ Less flexibility - ❌ Can't reuse existing resources
Factory (For Custom Setups)¶
from bast_ai_agno.bp.agno_agents import AgnoAgentFactory
from bast_ai_agno.bp.kb_resources import AgnoKnowledgeResources
from bast_ai_agno.dto.agent_configs import knowledge_agent_config
factory = AgnoAgentFactory("myapp")
kb_resources = AgnoKnowledgeResources("myapp")
knowledge = kb_resources.get_knowledge("my_kb")
agent = factory.create_openai_chat_agent(
name="my_agent",
model=factory._model_resources.get_open_ai_chat("gpt-4o-mini"),
db=factory._storage_resources.get_agent_storage("my_agent"),
knowledge=knowledge,
config_raw=knowledge_agent_config
)
Pros: - ✅ Full control over resources - ✅ Can reuse existing resources - ✅ Flexible configuration
Cons: - ❌ More setup code - ❌ Need to manage resources manually
Configurations (For Reusable Configs)¶
from bast_ai_agno.dto.agent_configs import knowledge_agent_config
# Just get the configuration dictionary
config = knowledge_agent_config
Pros: - ✅ Reusable configuration dictionaries - ✅ Can combine with utilities - ✅ Flexible
Cons: - ❌ Need to set up resources separately - ❌ More code for complete setup
Additional Resources¶
- Configuration Guide - Complete configuration guide
- Configuration Schema - Schema reference
- Examples - More examples
- Agno Agents Overview
Template Implementation Details¶
Templates are located in bast_ai_agno.bp.agent_templates and use:
- AgnoAgentFactory: For creating agents
- Resource Managers: For getting models, storage, knowledge, memory
- Preset Utilities: For optimized configurations
- Agent Configurations: For base configurations
All templates return fully configured Agent instances ready to use.