The Gap FastAgency Fills

AG2 (the community fork of AutoGen) is a powerful multi-agent framework. But taking an AG2 workflow from a Python script to a production application requires work: you need a web interface for users to interact with agents, a way to handle human-in-the-loop approvals, and a deployment pattern that keeps agents running reliably.

FastAgency adds a workflow abstraction layer and a set of UI adapters on top of AG2. The same workflow definition runs in a terminal (for development), a Mesop web app (for internal tools), or a FastAPI service (for API-accessible deployments) -- by swapping one line.

The Architecture

FastAgency has three layers:

  • Workflow: your AG2 agent logic, wrapped in a FastAgency workflow class
  • IO Adapter (UI): ConsoleUI (terminal), MesopUI (web), or FastAPIAdapter (REST API)
  • App: wires the workflow to the adapter and runs it
import fastagency
from fastagency import FastAgency
from fastagency.ui.console import ConsoleUI  # swap to MesopUI for web
from autogen import ConversableAgent
 
# Define your AG2 workflow inside a FastAgency workflow function
@fastagency.wf.register(name='research_task', description='Research a topic and produce a report')
def research_workflow(ui: fastagency.UIBase, params: dict) -> str:
    # AG2 agents defined inside the workflow
    user_proxy = ConversableAgent(
        name='user_proxy',
        human_input_mode='NEVER',
        max_consecutive_auto_reply=5,
    )
    researcher = ConversableAgent(
        name='researcher',
        system_message='You are a research assistant. Be concise and factual.',
        llm_config={'model': 'gpt-4o', 'api_key': 'YOUR_KEY'},
    )
 
    # Get input from the UI (works in console and web)
    topic = ui.text_input('What topic should I research?')
 
    # Run the agent conversation
    result = user_proxy.initiate_chat(
        researcher,
        message=f'Research this topic and write a 3-paragraph summary: {topic}',
    )
    return result.summary
 
# Wire to ConsoleUI and run
app = FastAgency(wf=fastagency.wf, ui=ConsoleUI())
app.start()
 

Switching from Console to Web (MesopUI)

Replace ConsoleUI with MesopUI and the same workflow runs as a web application. No changes to the workflow logic.

from fastagency.ui.mesop import MesopUI
 
# Everything else unchanged -- swap only this line
app = FastAgency(wf=fastagency.wf, ui=MesopUI())
 
# Run the Mesop web app
# fastagency run main.py
# Opens a browser UI at http://localhost:32123
 
MesopUI is built on Google's Mesop framework. It produces a clean chat-style interface without requiring any frontend development. It is not customisable beyond basic theming, but for internal tools this is usually sufficient.

FastAPI Adapter for API-Accessible Agents

For agents that should be callable by other services (webhook integrations, product backends), use FastAPIAdapter to expose the workflow as a REST API.

from fastagency.adapters.fastapi import FastAPIAdapter
from fastapi import FastAPI
 
server_app = FastAPI()
 
@server_app.on_event('startup')
async def startup():
    adapter = FastAPIAdapter(wf=fastagency.wf)
    server_app.include_router(adapter.router)
 
# Run: uvicorn main:server_app --host 0.0.0.0 --port 8008
# POST /run/{workflow_name} triggers the workflow
 

When FastAgency Is Worth Adding

FastAgency is worth using when:

  • You have AG2 workflows that need to be deployed as web apps or APIs without building custom UIs
  • You need to demo agent capabilities to non-technical stakeholders without writing frontend code
  • You want human-in-the-loop prompts (ui.text_input, ui.multiple_choice) that work in both terminal and web environments
  • You are building internal tools on top of AG2 agents

FastAgency adds overhead when:

  • Your AG2 workflow is already embedded in your own application with its own UI
  • You need a highly custom frontend (MesopUI's customisation is limited)
  • You are building a fully automated pipeline with no human-in-the-loop