AgentBuilder API¶
Complete API reference for the AgentBuilder and agent classes.
AgentBuilder¶
Constructor¶
| Parameter | Type | Description |
|---|---|---|
name |
str |
Unique name for the agent |
Methods¶
with_validator¶
Add a validator by registered name.
| Parameter | Type | Description |
|---|---|---|
validator_name |
str |
Name of validator in registry |
with_validator_instance¶
Add a validator instance directly.
| Parameter | Type | Description |
|---|---|---|
validator |
ValidatorInterface |
Validator instance |
with_data_model¶
Add a data model by registered name.
| Parameter | Type | Description |
|---|---|---|
model_name |
str |
Name of data model in registry |
with_data_model_instance¶
Add a data model instance directly.
| Parameter | Type | Description |
|---|---|---|
data_model |
DataModelInterface |
Data model instance |
with_search_handler¶
Add a search handler by registered name.
| Parameter | Type | Description |
|---|---|---|
handler_name |
str |
Name of search handler in registry |
with_search_handler_instance¶
Add a search handler instance directly.
| Parameter | Type | Description |
|---|---|---|
search_handler |
SearchHandlerInterface |
Search handler instance |
with_llm_service¶
Add an LLM service by registered name.
| Parameter | Type | Description |
|---|---|---|
service_name |
str |
Name of LLM service in registry |
with_llm_service_instance¶
Add an LLM service instance directly.
| Parameter | Type | Description |
|---|---|---|
llm_service |
LLMServiceInterface |
LLM service instance |
with_tools¶
Add tools for LangGraph workflows.
| Parameter | Type | Description |
|---|---|---|
tools |
list[Tool] |
List of Tool instances |
with_config¶
Add configuration dictionary.
| Parameter | Type | Description |
|---|---|---|
config |
Dict[str, Any] |
Configuration options |
with_langgraph¶
def with_langgraph(
self,
enable: bool = True,
config: Optional[Dict[str, Any]] = None
) -> "AgentBuilder"
Enable LangGraph workflow.
| Parameter | Type | Default | Description |
|---|---|---|---|
enable |
bool |
True |
Enable LangGraph |
config |
Dict[str, Any] |
None |
LangGraph configuration |
build¶
Build and return the configured agent.
Returns: CustomAgent or LangGraphAgent instance
Raises: ValueError if named component not found in registry
CustomAgent¶
Constructor¶
CustomAgent(
name: str,
validator: Optional[ValidatorInterface] = None,
data_model: Optional[DataModelInterface] = None,
search_handler: Optional[SearchHandlerInterface] = None,
llm_service: Optional[LLMServiceInterface] = None,
config: Optional[Dict[str, Any]] = None,
)
| Parameter | Type | Default | Description |
|---|---|---|---|
name |
str |
- | Agent name |
validator |
ValidatorInterface |
None |
Input validator |
data_model |
DataModelInterface |
None |
Data model validator |
search_handler |
SearchHandlerInterface |
None |
Search handler |
llm_service |
LLMServiceInterface |
None |
LLM service |
config |
Dict[str, Any] |
None |
Configuration |
Methods¶
initialize¶
Initialize the agent with configuration.
process_request¶
Process a request and return a response.
Request Format:
{
"query": str, # User query (required)
"system_message": str, # System prompt
"max_tokens": int, # Max response tokens
"temperature": float, # LLM temperature
"chat_history": list, # Previous messages
"user_id": str, # User identifier
"chat_id": str, # Chat session ID
"metadata": dict, # Additional metadata
}
Response Format:
{
"success": bool,
"agent": str,
"search_results": list,
"llm_response": {
"response": str,
"model_info": dict,
"token_usage": dict,
},
"validation_errors": list, # If validation failed
"error": str, # If error occurred
}
get_agent_name¶
Returns the agent's name.
LangGraphAgent¶
Constructor¶
LangGraphAgent(
name: str,
base_agent: CustomAgent,
tools: list = None,
config: Optional[Dict[str, Any]] = None,
)
| Parameter | Type | Default | Description |
|---|---|---|---|
name |
str |
- | Agent name |
base_agent |
CustomAgent |
- | Base CustomAgent |
tools |
list |
None |
Tools for workflow |
config |
Dict[str, Any] |
None |
Workflow configuration |
Methods¶
initialize¶
Initialize the LangGraph workflow.
process_request¶
Process request using LangGraph workflow.
Enhanced Response Format:
{
"success": bool,
"agent": str,
"llm_response": {
"response": str,
"model_info": dict,
"token_usage": dict,
"chat_id": str,
"tools_used": list,
},
"workflow_metadata": {
"status": str,
"tools_used": list,
"tool_results": list,
},
"search_results": list,
}
get_chat_history¶
Fetch chat history from DynamoDB or use provided history.
create_langgraph_agent¶
def create_langgraph_agent(
name: str,
llm_service: LLMServiceInterface,
tools: Optional[list] = None,
validator: Optional[ValidatorInterface] = None,
search_handler: Optional[SearchHandlerInterface] = None,
data_model: Optional[DataModelInterface] = None,
config: Optional[Dict[str, Any]] = None,
) -> LangGraphAgent
Factory function to create a LangGraph-enabled agent.
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
name |
str |
- | Agent name |
llm_service |
LLMServiceInterface |
- | LLM service (required) |
tools |
list |
None |
Tools for the agent |
validator |
ValidatorInterface |
None |
Input validator |
search_handler |
SearchHandlerInterface |
None |
Search handler |
data_model |
DataModelInterface |
None |
Data model |
config |
Dict[str, Any] |
None |
Configuration |
Configuration Options¶
| Key | Type | Default | Description |
|---|---|---|---|
enable_validation |
bool |
True |
Enable input validation |
enable_tools |
bool |
True if tools |
Enable tool usage |
enable_search |
bool |
True if handler |
Enable search |
enable_tracing |
bool |
False |
Enable LangSmith |
max_iterations |
int |
10 |
Max workflow iterations |
temperature |
float |
0.1 |
LLM temperature |
Returns¶
LangGraphAgent configured with ToolUseWorkflow.
Example¶
from akordi_agents.core import create_langgraph_agent
from akordi_agents.services import AWSBedrockService
agent = create_langgraph_agent(
name="my_agent",
llm_service=AWSBedrockService(),
tools=[WeatherTool()],
config={
"enable_tools": True,
"temperature": 0.1,
}
)
response = agent.process_request({
"query": "What's the weather?",
"system_message": "You are helpful.",
})
Registry Functions¶
register_validator¶
Register a validator class for use with AgentBuilder.
register_llm_service¶
Register an LLM service class.
register_search_handler¶
Register a search handler class.
register_data_model¶
Register a data model class.
get_validator¶
Get a registered validator class by name.
get_llm_service¶
Get a registered LLM service class by name.
get_search_handler¶
Get a registered search handler class by name.
get_data_model¶
Get a registered data model class by name.