Agent Management Example¶
This guide provides a professional, step-by-step walkthrough for creating, registering, and controlling an agent using the AgentManager
and Agent
classes from the agenticaiframework
package.
It is intended for developers building intelligent systems that require autonomous or semi-autonomous agents.
Prerequisites & Configuration¶
- Installation: Ensure
agenticaiframework
is installed and accessible in your Python environment. - No additional configuration is required for this example.
- Python Version: Compatible with Python 3.8+.
Code¶
from agenticaiframework.agents import AgentManager, Agent
if __name__ == "__main__":
agent_manager = AgentManager()
# Create and register an agent
example_agent = Agent(name="ExampleAgent")
agent_manager.register_agent(example_agent)
# Control the agent
example_agent.start()
example_agent.pause()
example_agent.resume()
example_agent.stop()
# List registered agents
print("Registered Agents:", [agent.name for agent in agent_manager.agents])
# Retrieve a specific agent
retrieved_agent = agent_manager.get_agent("ExampleAgent")
print("Retrieved Agent:", retrieved_agent.name)
Step-by-Step Execution¶
-
Import Required Classes
ImportAgentManager
andAgent
fromagenticaiframework.agents
. -
Instantiate the Agent Manager
Create an instance ofAgentManager
to handle agent registration and lifecycle management. -
Create an Agent
Instantiate anAgent
with a unique name. -
Register the Agent
Useregister_agent
to add the agent to the manager's registry. -
Control the Agent
Usestart
,pause
,resume
, andstop
to manage the agent's lifecycle. -
List Registered Agents
Access theagents
list to see all registered agents. -
Retrieve a Specific Agent
Useget_agent
to fetch an agent by name.
Best Practice: Assign meaningful names to agents to make debugging and monitoring easier.
Expected Input¶
No user input is required; the script uses hardcoded values for demonstration purposes. In production, agent names and behaviors could be dynamically configured based on application needs.
Expected Output¶
[YYYY-MM-DD HH:MM:SS] [Agent:ExampleAgent] Agent ExampleAgent started.
[YYYY-MM-DD HH:MM:SS] [Agent:ExampleAgent] Agent ExampleAgent paused.
[YYYY-MM-DD HH:MM:SS] [Agent:ExampleAgent] Agent ExampleAgent resumed.
[YYYY-MM-DD HH:MM:SS] [Agent:ExampleAgent] Agent ExampleAgent stopped.
Registered Agents: ['ExampleAgent']
Retrieved Agent: ExampleAgent
How to Run¶
Run the example from the project root:
python examples/agents_example.py
If installed as a package, you can also run it from anywhere:
python -m examples.agents_example
Tip: Integrate
AgentManager
with monitoring and task management systems for full lifecycle control of agents in production environments.