agents.patterns.simple_rag_agent_pattern¶
Simple RAG Agent Pattern - Using SimpleAgentV3 as base for RAG implementation.
This module demonstrates creating a RAG (Retrieval-Augmented Generation) agent using SimpleAgentV3 as the foundation, following the user’s request to use agent.py and SimpleAgentV3 patterns.
The pattern shows: 1. Extending SimpleAgentV3 for specialized functionality 2. Proper state schema composition 3. Tool integration for retrieval 4. Structured output for answers
Classes¶
Structured answer with source citations. |
|
Hybrid RAG Agent combining multiple retrieval strategies. |
|
Iterative RAG Agent that refines answers through multiple retrievals. |
|
Structured retrieval result. |
|
Simple RAG Agent built on SimpleAgentV3 foundation. |
Functions¶
|
Create a hybrid RAG agent with multiple retrieval strategies. |
|
Create an iterative RAG agent for complex queries. |
|
Create a simple RAG agent with sensible defaults. |
Example of hybrid retrieval. |
|
Example of iterative refinement. |
|
Example of using SimpleRAGAgent. |
|
|
Retrieve documents based on query. |
Module Contents¶
- class agents.patterns.simple_rag_agent_pattern.AnswerWithSources(/, **data)¶
Bases:
pydantic.BaseModel
Structured answer with source citations.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class agents.patterns.simple_rag_agent_pattern.HybridRAGAgent¶
Bases:
SimpleRAGAgent
Hybrid RAG Agent combining multiple retrieval strategies.
This variant uses multiple retrieval approaches: - Semantic similarity search - Keyword-based retrieval - Knowledge graph traversal - Combines results for comprehensive answers
- setup_agent()¶
Setup hybrid retrieval tools.
- Return type:
None
- class agents.patterns.simple_rag_agent_pattern.IterativeRAGAgent¶
Bases:
SimpleRAGAgent
Iterative RAG Agent that refines answers through multiple retrievals.
This variant performs iterative retrieval and refinement: 1. Initial retrieval and answer generation 2. Identifies gaps or unclear areas 3. Performs targeted follow-up retrievals 4. Refines the answer with additional context
- setup_agent()¶
Setup iterative RAG configuration.
- Return type:
None
- class agents.patterns.simple_rag_agent_pattern.RetrievalResult(/, **data)¶
Bases:
pydantic.BaseModel
Structured retrieval result.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class agents.patterns.simple_rag_agent_pattern.SimpleRAGAgent¶
Bases:
SimpleAgentV3
Simple RAG Agent built on SimpleAgentV3 foundation.
This agent extends SimpleAgentV3 to provide RAG capabilities: - Document retrieval through tools - Context-aware answer generation - Source attribution - Structured output with confidence scores
Examples
>>> rag_agent = SimpleRAGAgent( ... name="knowledge_assistant", ... temperature=0.3, ... debug=True ... ) >>> result = await rag_agent.arun("What is quantum computing?")
- setup_agent()¶
Setup RAG-specific configuration.
- Return type:
None
- agents.patterns.simple_rag_agent_pattern.create_hybrid_rag_agent(name='hybrid_rag', retrieval_strategies=None, **kwargs)¶
Create a hybrid RAG agent with multiple retrieval strategies.
- Parameters:
- Return type:
- agents.patterns.simple_rag_agent_pattern.create_iterative_rag_agent(name='iterative_rag', max_iterations=3, **kwargs)¶
Create an iterative RAG agent for complex queries.
- Parameters:
- Return type:
- agents.patterns.simple_rag_agent_pattern.create_simple_rag_agent(name='rag_assistant', temperature=0.3, debug=True, **kwargs)¶
Create a simple RAG agent with sensible defaults.
- Parameters:
- Return type:
- async agents.patterns.simple_rag_agent_pattern.example_hybrid_rag()¶
Example of hybrid retrieval.
- async agents.patterns.simple_rag_agent_pattern.example_iterative_rag()¶
Example of iterative refinement.
- async agents.patterns.simple_rag_agent_pattern.example_simple_rag()¶
Example of using SimpleRAGAgent.