Skip to content

Getting Started with FastAgency#

The fastest way to bring multi-agent workflows to production.


Test Passing Coverage Downloads Package version Supported Python versions
CodeQL Dependency Review License Code of Conduct Discord


Welcome to FastAgency! This guide will walk you through the initial setup and usage of FastAgency, a powerful tool that leverages the AutoGen framework to quickly build applications. FastAgency is designed to be flexible and adaptable, and we plan to extend support to additional agentic frameworks such as CrewAI in the near future. This will provide even more options for defining workflows and integrating with various AI tools.

With FastAgency, you can create interactive applications using various interfaces such as a console or Mesop.

Supported Interfaces#

FastAgency currently supports workflows defined using AutoGen and provides options for different types of applications:

  • Console: Use the ConsoleUI interface for command-line based interaction. This is ideal for developing and testing workflows in a text-based environment.
  • Mesop: Utilize Mesop with MesopUI for web-based applications. This interface is suitable for creating web applications with a user-friendly interface.

We are also working on adding support for other frameworks, such as CrewAI, to broaden the scope and capabilities of FastAgency. Stay tuned for updates on these integrations.

Quick start#

Install#

To get started, you need to install FastAgency. You can do this using pip, Python's package installer. Choose the installation command based on the interface you want to use:

pip install "fastagency[autogen]"

This command installs FastAgency with support for the Console interface and AutoGen framework.

pip install "fastagency[autogen,mesop]"

This command installs FastAgency with support for both the Console and Mesop interfaces, providing a more comprehensive setup.

Using older AutoGen version 0.2.x

In case you want to use an older version of AutoGen (pyautogen instead of autogen package ), please use the following pip command:

pip install "fastagency[pyautogen]"

This command installs FastAgency with support for the Console interface and AutoGen framework.

pip install "fastagency[pyautogen,mesop]"

Imports#

Depending on the interface you choose, you'll need to import different modules. These imports set up the necessary components for your application:

import os

from autogen.agentchat import ConversableAgent

from fastagency import UI, FastAgency, Workflows
from fastagency.runtime.autogen.base import AutoGenWorkflows
from fastagency.ui.console import ConsoleUI

For Console applications, import ConsoleUI to handle command-line input and output.

import os

from autogen.agentchat import ConversableAgent

from fastagency import UI, FastAgency, Workflows
from fastagency.runtime.autogen.base import AutoGenWorkflows
from fastagency.ui.mesop import MesopUI

For Mesop applications, import MesopUI to integrate with the Mesop web interface.

Define Workflow#

You need to define the workflow that your application will use. This is where you specify how the agents interact and what they do. Here's a simple example of a workflow definition:

    "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: Workflows, 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  # type: ignore[no-any-return]

This code snippet sets up a simple learning chat between a student and a teacher. You define the agents and how they should interact, specifying how the conversation should be summarized.

Define FastAgency Application#

Next, define your FastAgency application. This ties together your workflow and the interface you chose:

app = FastAgency(wf=wf, ui=ConsoleUI())

For Console applications, use ConsoleUI to handle user interaction via the command line.

app = FastAgency(wf=wf, ui=MesopUI())

For Mesop applications, use MesopUI to enable web-based interactions.

Complete Application Code#

Console
import os

from autogen.agentchat import ConversableAgent

from fastagency import UI, FastAgency, Workflows
from fastagency.runtime.autogen.base import AutoGenWorkflows
from fastagency.ui.console import ConsoleUI

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: Workflows, 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  # type: ignore[no-any-return]


app = FastAgency(wf=wf, ui=ConsoleUI())
Mesop
import os

from autogen.agentchat import ConversableAgent

from fastagency import UI, FastAgency, Workflows
from fastagency.runtime.autogen.base import AutoGenWorkflows
from fastagency.ui.mesop import MesopUI

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: Workflows, 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  # type: ignore[no-any-return]


app = FastAgency(wf=wf, ui=MesopUI())

Run Application#

Once everything is set up, you can run your FastAgency application using the following command:

fastagency run

Output#

The output will vary based on the interface:

╭─ Python module file ─╮
│                      │
│  🐍 main.py          │
│                      │
╰──────────────────────╯


╭─ Importable FastAgency app ─╮
│                             │
│  from main import app       │
│                             │
╰─────────────────────────────╯

╭─ FastAgency -> user [text_input] ────────────────────────────────────────────╮
│                                                                              │
│ Starting a new workflow 'simple_learning' with the following                 │
│ description:                                                                 │
│                                                                              │
│ Student and teacher learning chat                                            │
│                                                                              │
│ Please enter an                                                              │
│ initial message:                                                             │
╰──────────────────────────────────────────────────────────────────────────────╯

For Console applications, you will see a command-line prompt where you can enter the initial message and interact with your workflow.

╭─ Python module file ─╮
│                      │
│  🐍 main_mesop.py    │
│                      │
╰──────────────────────╯


╭─ Importable FastAgency app ──╮
│                              │
│  from main_mesop import app  │
│                              │
╰──────────────────────────────╯

Running with hot reload:

Running server on: http://localhost:32123
* Serving Flask app 'mesop.server.server'
* Debug mode: off

For Mesop applications, the output will include a URL where you can access your web-based application.

Future Plans#

We are actively working on expanding FastAgency’s capabilities. In addition to supporting AutoGen, we plan to integrate support for other frameworks, such as CrewAI, to provide more flexibility and options for building applications. This will allow you to define workflows using a variety of frameworks and leverage their unique features and functionalities.


Stay in touch#

Please show your support and stay in touch by:

Your support helps us to stay in touch with you and encourages us to continue developing and improving the framework. Thank you for your support!


Contributors#

Thanks to all of these amazing people who made the project better!