Skip to content

AgentBuilder API

Complete API reference for the AgentBuilder and agent classes.

AgentBuilder

class AgentBuilder:
    """Builder class for creating custom agents with fluent interface."""

Constructor

AgentBuilder(name: str)
Parameter Type Description
name str Unique name for the agent

Methods

with_validator

def with_validator(self, validator_name: str) -> "AgentBuilder"

Add a validator by registered name.

Parameter Type Description
validator_name str Name of validator in registry

with_validator_instance

def with_validator_instance(self, validator: ValidatorInterface) -> "AgentBuilder"

Add a validator instance directly.

Parameter Type Description
validator ValidatorInterface Validator instance

with_data_model

def with_data_model(self, model_name: str) -> "AgentBuilder"

Add a data model by registered name.

Parameter Type Description
model_name str Name of data model in registry

with_data_model_instance

def with_data_model_instance(self, data_model: DataModelInterface) -> "AgentBuilder"

Add a data model instance directly.

Parameter Type Description
data_model DataModelInterface Data model instance

with_search_handler

def with_search_handler(self, handler_name: str) -> "AgentBuilder"

Add a search handler by registered name.

Parameter Type Description
handler_name str Name of search handler in registry

with_search_handler_instance

def with_search_handler_instance(self, search_handler: SearchHandlerInterface) -> "AgentBuilder"

Add a search handler instance directly.

Parameter Type Description
search_handler SearchHandlerInterface Search handler instance

with_llm_service

def with_llm_service(self, service_name: str) -> "AgentBuilder"

Add an LLM service by registered name.

Parameter Type Description
service_name str Name of LLM service in registry

with_llm_service_instance

def with_llm_service_instance(self, llm_service: LLMServiceInterface) -> "AgentBuilder"

Add an LLM service instance directly.

Parameter Type Description
llm_service LLMServiceInterface LLM service instance

with_tools

def with_tools(self, tools: list) -> "AgentBuilder"

Add tools for LangGraph workflows.

Parameter Type Description
tools list[Tool] List of Tool instances

with_config

def with_config(self, config: Dict[str, Any]) -> "AgentBuilder"

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

def build(self) -> Union[CustomAgent, LangGraphAgent]

Build and return the configured agent.

Returns: CustomAgent or LangGraphAgent instance

Raises: ValueError if named component not found in registry


CustomAgent

class CustomAgent(AgentInterface):
    """A configurable agent that uses injected components."""

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

def initialize(self, config: Dict[str, Any]) -> None

Initialize the agent with configuration.

process_request

def process_request(self, request_data: Dict[str, Any]) -> Dict[str, Any]

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

def get_agent_name(self) -> str

Returns the agent's name.


LangGraphAgent

class LangGraphAgent(AgentInterface):
    """LangGraph-enabled agent wrapper with ToolUseWorkflow."""

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

def initialize(self, config: Dict[str, Any]) -> None

Initialize the LangGraph workflow.

process_request

def process_request(self, request_data: Dict[str, Any]) -> Dict[str, Any]

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

def get_chat_history(self, request_data: Dict[str, Any]) -> List[Dict[str, Any]]

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

def register_validator(name: str, validator_class: type) -> None

Register a validator class for use with AgentBuilder.

register_llm_service

def register_llm_service(name: str, service_class: type) -> None

Register an LLM service class.

register_search_handler

def register_search_handler(name: str, handler_class: type) -> None

Register a search handler class.

register_data_model

def register_data_model(name: str, model_class: type) -> None

Register a data model class.

get_validator

def get_validator(name: str) -> Optional[type]

Get a registered validator class by name.

get_llm_service

def get_llm_service(name: str) -> Optional[type]

Get a registered LLM service class by name.

get_search_handler

def get_search_handler(name: str) -> Optional[type]

Get a registered search handler class by name.

get_data_model

def get_data_model(name: str) -> Optional[type]

Get a registered data model class by name.