Closed davorrunje closed 1 month ago
import os
from autogen.agentchat import ConversableAgent
from fastagency import UI
from fastagency.ui.console import ConsoleUI, FastAPIUI
from fastagency.runtime.autogen.base import AutoGenWorkflows
from fastagency import FastAgency
llm_config = {
"config_list": [
{
"model": "gpt-4o",
"api_key": os.getenv("OPENAI_API_KEY"),
}
],
"temperature": 0.0,
}
wf = AutoGenWorkflows()
@wf.register(name="simple_learning", description="Student and teacher learning chat")
def simple_workflow(wf: AutoGenWorkflows, ui: UI, initial_message: str, session_id: str) -> str:
student_agent = ConversableAgent(
name="Student_Agent",
system_message="You are a student willing to learn.",
llm_config=llm_config,
)
teacher_agent = ConversableAgent(
name="Teacher_Agent",
system_message="You are a math teacher.",
llm_config=llm_config,
)
chat_result = student_agent.initiate_chat(
teacher_agent,
message=initial_message,
summary_method="reflection_with_llm",
max_turns=5,
)
return chat_result.summary
ui=FastAPIUI(nats_params=..., no_workers=10)
fa_app = FastAgency(wf=wf, ui=ui)
app = FastAPI(lifespan=fa_app.lifespan(fa_app))
# do whatever you want with the app
...
def some_route():
web_socket_info = fa_app.run_workflow("simple_learning", "Hello, teacher!", "session_id")
From Reddit:
https://www.reddit.com/r/AutoGenAI/comments/1fj1yq9/handling_multiple_users_at_the_same_time/
I have a 3-agent system written in AutoGen. I want to wrap that around in an API and expose that to an existing web app. This is not a chat application. It's an agent that takes in a request and processes it using various specialized agents. The end result is a json. I want this agentic system to be used by 100s of users at the same time. How do I make sure that the agent system i wrote can scale up and can maintain the states of each user connecting to it?