Base Agent Module
Base module for Django agents
- exception django_agents.base.AgentValidationError[source]
Bases:
AgentExceptionValidation error for the execution context
- exception django_agents.base.AgentExecutionError[source]
Bases:
AgentExceptionError raised when the agent execution fails
- class django_agents.base.BaseAgent[source]
Bases:
ABCBase class for every Django agent.
All agents must inherit from this class and implement the execute() method.
- abstractmethod execute(context: Dict[str, Any]) Dict[str, Any][source]
Executes the main agent logic
- Parameters:
context – Dictionary containing the execution context
- Returns:
Execution result as a dictionary
- Raises:
AgentExecutionError – If something goes wrong during execution
- validate_context(context: Dict[str, Any]) bool[source]
Validates the provided context
- Parameters:
context – Context to validate
- Returns:
True when the context is valid
- Raises:
AgentValidationError – If the context is not valid
- pre_execute(context: Dict[str, Any]) Dict[str, Any][source]
Hook executed before the main execution
- Parameters:
context – Execution context
- Returns:
Updated or original context
- post_execute(result: Dict[str, Any], context: Dict[str, Any]) Dict[str, Any][source]
Hook executed after the main execution
- Parameters:
result – Execution result
context – Execution context
- Returns:
Updated or original result
- run(context: Dict[str, Any] | None = None) Dict[str, Any][source]
Main entry point to run the agent
- Parameters:
context – Execution context
- Returns:
Execution result
- Raises:
AgentValidationError – If the context is invalid
AgentExecutionError – If an error occurs during execution
- class django_agents.base.AsyncAgent[source]
Bases:
BaseAgentBase class for asynchronous agents.
Extends BaseAgent and adds support for asynchronous execution through Celery or other task queues.
- class django_agents.base.WorkflowAgent[source]
Bases:
BaseAgentAgent specialized in managing workflows.
A workflow is a sequence of agents executed in a defined order.
BaseAgent
- class django_agents.base.BaseAgent[source]
Bases:
ABCBase class for every Django agent.
All agents must inherit from this class and implement the execute() method.
- abstractmethod execute(context: Dict[str, Any]) Dict[str, Any][source]
Executes the main agent logic
- Parameters:
context – Dictionary containing the execution context
- Returns:
Execution result as a dictionary
- Raises:
AgentExecutionError – If something goes wrong during execution
- validate_context(context: Dict[str, Any]) bool[source]
Validates the provided context
- Parameters:
context – Context to validate
- Returns:
True when the context is valid
- Raises:
AgentValidationError – If the context is not valid
- pre_execute(context: Dict[str, Any]) Dict[str, Any][source]
Hook executed before the main execution
- Parameters:
context – Execution context
- Returns:
Updated or original context
- post_execute(result: Dict[str, Any], context: Dict[str, Any]) Dict[str, Any][source]
Hook executed after the main execution
- Parameters:
result – Execution result
context – Execution context
- Returns:
Updated or original result
- run(context: Dict[str, Any] | None = None) Dict[str, Any][source]
Main entry point to run the agent
- Parameters:
context – Execution context
- Returns:
Execution result
- Raises:
AgentValidationError – If the context is invalid
AgentExecutionError – If an error occurs during execution
AsyncAgent
- class django_agents.base.AsyncAgent[source]
Bases:
BaseAgentBase class for asynchronous agents.
Extends BaseAgent and adds support for asynchronous execution through Celery or other task queues.
WorkflowAgent
- class django_agents.base.WorkflowAgent[source]
Bases:
BaseAgentAgent specialized in managing workflows.
A workflow is a sequence of agents executed in a defined order.
Exceptions
- exception django_agents.base.AgentValidationError[source]
Bases:
AgentExceptionValidation error for the execution context
- exception django_agents.base.AgentExecutionError[source]
Bases:
AgentExceptionError raised when the agent execution fails