2024-06-25 14:27:45 -07:00
|
|
|
import asyncio
|
|
|
|
|
|
|
|
from agnext.application import SingleThreadedAgentRuntime
|
2024-06-28 15:50:10 -07:00
|
|
|
from agnext.components.models import OpenAIChatCompletionClient, UserMessage
|
|
|
|
from team_one.agents.coder import Coder, Executor
|
|
|
|
from team_one.agents.orchestrator import RoundRobinOrchestrator
|
|
|
|
from team_one.messages import BroadcastMessage
|
2024-06-25 14:27:45 -07:00
|
|
|
|
|
|
|
|
|
|
|
async def main() -> None:
|
|
|
|
# Create the runtime.
|
|
|
|
runtime = SingleThreadedAgentRuntime()
|
|
|
|
|
2024-06-28 15:50:10 -07:00
|
|
|
client = OpenAIChatCompletionClient(model="gpt-4o")
|
|
|
|
|
2024-06-25 14:27:45 -07:00
|
|
|
# Register agents.
|
2024-06-28 15:50:10 -07:00
|
|
|
coder = runtime.register_and_get_proxy(
|
|
|
|
"Coder",
|
|
|
|
lambda: Coder(model_client=client),
|
2024-06-25 14:27:45 -07:00
|
|
|
)
|
2024-06-28 15:50:10 -07:00
|
|
|
executor = runtime.register_and_get_proxy("Executor", lambda: Executor("A agent for executing code"))
|
|
|
|
|
|
|
|
runtime.register("orchestrator", lambda: RoundRobinOrchestrator([coder, executor]))
|
2024-06-25 14:27:45 -07:00
|
|
|
|
2024-06-28 15:50:10 -07:00
|
|
|
task = input("Enter a task: ")
|
2024-06-25 14:27:45 -07:00
|
|
|
|
2024-06-28 15:50:10 -07:00
|
|
|
await runtime.publish_message(
|
|
|
|
BroadcastMessage(content=UserMessage(content=task, source="human")), namespace="default"
|
|
|
|
)
|
2024-06-25 14:27:45 -07:00
|
|
|
|
|
|
|
# Run the runtime until the task is completed.
|
2024-06-28 15:50:10 -07:00
|
|
|
await runtime.process_until_idle()
|
2024-06-25 14:27:45 -07:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import logging
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.WARNING)
|
|
|
|
logging.getLogger("agnext").setLevel(logging.DEBUG)
|
|
|
|
asyncio.run(main())
|