Agent Registry Module
Agent Registry for auto-discovery and centralized agent management.
The registry automatically discovers and registers all agents across installed Django apps, providing a centralized access point for agent management.
- class django_agents.registry.AgentRegistry[source]
Bases:
objectCentralized registry for managing Django agents.
The registry provides auto-discovery, registration, and lookup capabilities for all agents in the project.
- register(agent_class: Type[BaseAgent], app_name: str, force: bool = False) None[source]
Register an agent class.
- Parameters:
agent_class – Agent class to register
app_name – Name of the app containing the agent
force – Force registration even if agent exists
- Raises:
ValueError – If agent is already registered and force=False
- unregister(agent_name: str) None[source]
Unregister an agent.
- Parameters:
agent_name – Name of the agent to unregister
- Raises:
KeyError – If agent is not registered
- get_agent(agent_name: str) BaseAgent | None[source]
Get an agent instance by name.
- Parameters:
agent_name – Name of the agent
- Returns:
Agent instance or None if not found
- get_agent_class(agent_name: str) Type[BaseAgent] | None[source]
Get an agent class by name.
- Parameters:
agent_name – Name of the agent
- Returns:
Agent class or None if not found
- get_agent_metadata(agent_name: str) Dict | None[source]
Get agent metadata.
- Parameters:
agent_name – Name of the agent
- Returns:
Agent metadata dictionary or None if not found
- list_agents(app_name: str | None = None, enabled_only: bool = False) List[Dict][source]
List all registered agents.
- Parameters:
app_name – Filter by app name
enabled_only – Only return enabled agents
- Returns:
List of agent metadata dictionaries
- get_agents_by_app(app_name: str) List[Dict][source]
Get all agents from a specific app.
- Parameters:
app_name – Name of the app
- Returns:
List of agent metadata dictionaries
- is_registered(agent_name: str) bool[source]
Check if an agent is registered.
- Parameters:
agent_name – Name of the agent
- Returns:
True if registered, False otherwise
- autodiscover(force: bool = False) None[source]
Automatically discover and register all agents in installed apps.
- Parameters:
force – Force re-discovery even if already discovered
- django_agents.registry.autodiscover()[source]
Convenience function to auto-discover agents.
This should be called during Django app initialization.
- django_agents.registry.get_registry() AgentRegistry[source]
Get the global agent registry instance.
- Returns:
Global agent registry
AgentRegistry
- class django_agents.registry.AgentRegistry[source]
Bases:
objectCentralized registry for managing Django agents.
The registry provides auto-discovery, registration, and lookup capabilities for all agents in the project.
- register(agent_class: Type[BaseAgent], app_name: str, force: bool = False) None[source]
Register an agent class.
- Parameters:
agent_class – Agent class to register
app_name – Name of the app containing the agent
force – Force registration even if agent exists
- Raises:
ValueError – If agent is already registered and force=False
Register a new agent class in the registry.
- unregister(agent_name: str) None[source]
Unregister an agent.
- Parameters:
agent_name – Name of the agent to unregister
- Raises:
KeyError – If agent is not registered
Remove an agent from the registry.
- get_agent(agent_name: str) BaseAgent | None[source]
Get an agent instance by name.
- Parameters:
agent_name – Name of the agent
- Returns:
Agent instance or None if not found
Get a fresh instance of a registered agent.
- get_agent_class(agent_name: str) Type[BaseAgent] | None[source]
Get an agent class by name.
- Parameters:
agent_name – Name of the agent
- Returns:
Agent class or None if not found
Get the agent class by name.
- get_agent_metadata(agent_name: str) Dict | None[source]
Get agent metadata.
- Parameters:
agent_name – Name of the agent
- Returns:
Agent metadata dictionary or None if not found
Get agent metadata dictionary.
- list_agents(app_name: str | None = None, enabled_only: bool = False) List[Dict][source]
List all registered agents.
- Parameters:
app_name – Filter by app name
enabled_only – Only return enabled agents
- Returns:
List of agent metadata dictionaries
List all registered agents with optional filtering.
- get_agents_by_app(app_name: str) List[Dict][source]
Get all agents from a specific app.
- Parameters:
app_name – Name of the app
- Returns:
List of agent metadata dictionaries
Get all agents from a specific Django app.
- is_registered(agent_name: str) bool[source]
Check if an agent is registered.
- Parameters:
agent_name – Name of the agent
- Returns:
True if registered, False otherwise
Check if an agent is registered.
- count() int[source]
Get the number of registered agents.
- Returns:
Number of registered agents
Get the total number of registered agents.
- autodiscover(force: bool = False) None[source]
Automatically discover and register all agents in installed apps.
- Parameters:
force – Force re-discovery even if already discovered
Automatically discover and register agents from all installed apps.
- export_metadata() Dict[source]
Export all agent metadata as a dictionary.
- Returns:
Dictionary containing all agent metadata
Export all agent metadata as a dictionary.
- register(agent_class: Type[BaseAgent], app_name: str, force: bool = False) None[source]
Register an agent class.
- Parameters:
agent_class – Agent class to register
app_name – Name of the app containing the agent
force – Force registration even if agent exists
- Raises:
ValueError – If agent is already registered and force=False
- unregister(agent_name: str) None[source]
Unregister an agent.
- Parameters:
agent_name – Name of the agent to unregister
- Raises:
KeyError – If agent is not registered
- get_agent(agent_name: str) BaseAgent | None[source]
Get an agent instance by name.
- Parameters:
agent_name – Name of the agent
- Returns:
Agent instance or None if not found
- get_agent_class(agent_name: str) Type[BaseAgent] | None[source]
Get an agent class by name.
- Parameters:
agent_name – Name of the agent
- Returns:
Agent class or None if not found
- get_agent_metadata(agent_name: str) Dict | None[source]
Get agent metadata.
- Parameters:
agent_name – Name of the agent
- Returns:
Agent metadata dictionary or None if not found
- list_agents(app_name: str | None = None, enabled_only: bool = False) List[Dict][source]
List all registered agents.
- Parameters:
app_name – Filter by app name
enabled_only – Only return enabled agents
- Returns:
List of agent metadata dictionaries
- get_agents_by_app(app_name: str) List[Dict][source]
Get all agents from a specific app.
- Parameters:
app_name – Name of the app
- Returns:
List of agent metadata dictionaries
- is_registered(agent_name: str) bool[source]
Check if an agent is registered.
- Parameters:
agent_name – Name of the agent
- Returns:
True if registered, False otherwise
- autodiscover(force: bool = False) None[source]
Automatically discover and register all agents in installed apps.
- Parameters:
force – Force re-discovery even if already discovered
Global Functions
- django_agents.registry.autodiscover()[source]
Convenience function to auto-discover agents.
This should be called during Django app initialization.
- django_agents.registry.get_registry() AgentRegistry[source]
Get the global agent registry instance.
- Returns:
Global agent registry