Now, we have a decision to make, either we can continue developing our own version of AI Agentic implementation or instead of re-inventing the wheel, start using an given AI Agent framework capabilities.
Standalone Implementation¶
# standalone implementation of an AI Agent
class MyFirstAgent():
def __init__(self) -> None:
super().__init__()
def do_something(self, message: str) -> None:
print(f"received message: {message}")
FirstAgent = MyFirstAgent()
FirstAgent.do_something("Hello World!")Use Case¶
To learn more about AI Agent implementation, Instead of building a TODO-List Tutorial, let’s focus on automating our HR Time Sheet process with AI Agents.
Solution Design : Implementation
Routed Agent¶
# refactor above code to use AutoGen Core framework
from autogen_core import RoutedAgent ## import AutoGen Core
class MyFirstAgent(RoutedAgent): ## pass RoutedAgent as base class
def __init__(self) -> None:
super().__init__("MyFirstAgent") ## Agent Description
def do_something(self, message: str) -> None:
print(f"received message: {message}")
## commented below code because RoutedAgent
## are instantiated via runtime not standalone
## will see how to instantiate Agent class later
# FirstAgent = MyFirstAgent()
# FirstAgent.do_something("Hello World!")
## what is RoutedAgent class?
## take some time to understand super class Agent initialization
## read RoutedAgent base class implemenation signature
## what are the advantages of using this
RoutedAgent.__dict__from autogen_core import RoutedAgent
class TaskAgent(RoutedAgent): ## change Agent Name
def __init__(self) -> None:
super().__init__("ERPTaskAgent")
## add methods
def do_something(self, message: str) -> None: ## Refactor
# fetches tasks an employee ## Refactor
print(f"received message: {message}") ## Refactor
def do_something_more(self, message: str) -> None:## Refactor
# poeple working on one task ## Refactor
print(f"received message: {message}") ## Refactor
def do_something_even_more(self, message: str) -> None: ## Refactor
# approved PTOs for employee ## Refactor
# fetch all other teams working on same tasks
# and their PTO during same period## Refactor
print(f"received message: {message}") ## Refactorfrom autogen_core import RoutedAgent
class LLMAgent(RoutedAgent):
def __init__(self) -> None:
super().__init__("ERPLLMAgent")
def do_something(self, message: str) -> None:
# figure out Thursday and Friday date
print(f"received message: {message}")
def do_something_more(self, message: str) -> None:
# draft an approval request to manager
print(f"received message: {message}")
def do_something_even_more(self, message: str) -> None:
# greets and chat with Susan
print(f"received message: {message}")
def do_something_even_more(self, message: str) -> None:
# call next agent once
print(f"received message: {message}")
class ManagerAgent(RoutedAgent):
def __init__(self) -> None:
super().__init__("ERPMgrAgent")
def do_something(self, message: str) -> None:
# approve or disapprove PTO
print(f"received message: {message}")
def do_something_more(self, message: str) -> None:
# draft an approval request to manager
print(f"received message: {message}")
class BroadcasterAgent(RoutedAgent):
def __init__(self) -> None:
super().__init__("ERPBrdAgent")
def do_something(self, message: str) -> None:
# notify all employee that Susan is taking PTO
print(f"received message: {message}")
def do_something_more(self, message: str) -> None:
# draft an approval request to manager
print(f"received message: {message}")