Skip to content

Commit

Permalink
Getting started and Readme files updated (#298)
Browse files Browse the repository at this point in the history
* Getting started and Readme files updated

* polishing

* polishing
  • Loading branch information
davorrunje authored Oct 1, 2024
1 parent 913506b commit 35d37d2
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 99 deletions.
90 changes: 36 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,19 @@ With FastAgency, you can create interactive applications using various interface

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

- **Console**: Use the [ConsoleUI](https://fastagency.ai/latest/api/fastagency/ui/console/ConsoleUI/) interface for command-line based interaction. This is ideal for developing and testing workflows in a text-based environment.
- **Mesop**: Utilize [Mesop](https://google.github.io/mesop/) with [MesopUI](https://fastagency.ai/latest/api/fastagency/ui/mesop/MesopUI/) for web-based applications. This interface is suitable for creating web applications with a user-friendly interface.
- **Console**: Use the [ConsoleUI](https://fastagency.ai/0.2/api/fastagency/ui/console/ConsoleUI.md) interface for command-line based interaction. This is ideal for developing and testing workflows in a text-based environment.
- **Mesop**: Utilize [Mesop](https://google.github.io/mesop/) with [MesopUI](https://fastagency.ai/0.2/api/fastagency/ui/mesop/MesopUI.md) 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](https://www.crewai.com/), to broaden the scope and capabilities of FastAgency. Stay tuned for updates on these integrations.

## Install
## Quick start

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:
### Install

```console
pip install "fastagency[autogen]"
```

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

In case you want to use an older version of AutoGen (`pyautogen` instead of `autogen` package ), please use the following pip command:
To get started, you need to install FastAgency. You can do this using `pip`, Python's package installer. This command installs FastAgency with support for the [Mesop](https://google.github.io/mesop/) interface and AutoGen framework.

```console
pip install "fastagency[pyautogen]"
pip install "fastagency[autogen,mesop]"
```

## Write Code
Expand All @@ -92,15 +86,11 @@ import os

from autogen.agentchat import ConversableAgent

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

from fastagency import FastAgency
from fastagency.ui.mesop import MesopUI
```

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


### Define Workflow

Expand All @@ -119,8 +109,11 @@ llm_config = {

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:
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.",
Expand All @@ -136,7 +129,7 @@ def simple_workflow(wf: AutoGenWorkflows, ui: UI, initial_message: str, session_
teacher_agent,
message=initial_message,
summary_method="reflection_with_llm",
max_turns=5,
max_turns=3,
)

return chat_result.summary
Expand All @@ -149,50 +142,39 @@ This code snippet sets up a simple learning chat between a student and a teacher
Next, define your FastAgency application. This ties together your workflow and the interface you chose:

```python
from fastagency.ui.console import ConsoleUI

app = FastAgency(wf=wf, io=ConsoleUI())
app = FastAgency(wf=wf, ui=MesopUI(), title="Learning Chat")
```

## Run Application

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

```console
fastagency run
```
```
fastagency run
```

However, the preferred way of running Mesop application is a Python WSGI HTTP Server such as [Gunicorn](https://gunicorn.org/). First,
you need to install it using package manager such as `pip`:
```
pip install gunicorn
```
and then you can run it with:
```
gunicorn main:app
```

### Output

The output will vary based on the interface:
```console
[2024-10-01 16:18:59 +0000] [20390] [INFO] Starting gunicorn 23.0.0
[2024-10-01 16:18:59 +0000] [20390] [INFO] Listening at: http://127.0.0.1:8000 (20390)
[2024-10-01 16:18:59 +0000] [20390] [INFO] Using worker: sync
[2024-10-01 16:18:59 +0000] [20391] [INFO] Booting worker with pid: 20391
```

![Initial message](https://fastagency.ai/0.2/getting-started/images/chat.png?v1)

```console
╭─ 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: │
╰──────────────────────────────────────────────────────────────────────────────╯
```

---

## Future Plans

Expand All @@ -218,6 +200,6 @@ support!

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

<a href="https://github.com/airtai/fastagency/graphs/contributors">
<a href="https://github.com/airtai/fastagency/graphs/contributors" target="_blank">
<img src="https://contrib.rocks/image?repo=airtai/fastagency"/>
</a>
3 changes: 3 additions & 0 deletions docs/docs/en/getting-started/images/chat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 28 additions & 24 deletions docs/docs/en/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Next, define your FastAgency application. This ties together your workflow and t
=== "Console"

<details>
<summary>Console</summary>
<summary>main.py</summary>
```python
{!> docs_src/getting_started/main_console.py !}
```
Expand All @@ -175,7 +175,7 @@ Next, define your FastAgency application. This ties together your workflow and t
=== "Mesop"

<details>
<summary>Mesop</summary>
<summary>main.py</summary>
```python
{!> docs_src/getting_started/main_mesop.py !}
```
Expand All @@ -185,9 +185,27 @@ Next, define your FastAgency application. This ties together your workflow and t

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

```console
fastagency run
```
=== "Console"

```console
fastagency run
```

=== "Mesop"

```
fastagency run
```

However, the preferred way of running Mesop application is a Python WSGI HTTP Server such as [Gunicorn](https://gunicorn.org/). First,
you need to install it using package manager such as `pip`:
```
pip install gunicorn
```
and then you can run it with:
```
gunicorn main:app
```

### Output

Expand Down Expand Up @@ -224,27 +242,13 @@ The output will vary based on the interface:

=== "Mesop"
```console
╭─ 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
[2024-10-01 16:18:59 +0000] [20390] [INFO] Starting gunicorn 23.0.0
[2024-10-01 16:18:59 +0000] [20390] [INFO] Listening at: http://127.0.0.1:8000 (20390)
[2024-10-01 16:18:59 +0000] [20390] [INFO] Using worker: sync
[2024-10-01 16:18:59 +0000] [20391] [INFO] Booting worker with pid: 20391
```

For Mesop applications, the output will include a URL where you can access your web-based application.
![Initial message](./images/chat.png)



Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/getting_started/main_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from autogen.agentchat import ConversableAgent

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

llm_config = {
Expand Down Expand Up @@ -44,4 +44,4 @@ def simple_workflow(
return chat_result.summary # type: ignore[no-any-return]


app = FastAgency(wf=wf, ui=ConsoleUI())
app = FastAgency(wf=wf, ui=ConsoleUI(), title="Learning Chat")
2 changes: 1 addition & 1 deletion docs/docs_src/getting_started/main_mesop.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from autogen.agentchat import ConversableAgent

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

llm_config = {
Expand Down
26 changes: 14 additions & 12 deletions docs/docs_src/tutorial/giphy/simple_main.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
import os
from typing import Annotated, Any, Optional
from typing import Any

from autogen import register_function
from autogen import ConversableAgent, UserProxyAgent

from fastagency import UI, FastAgency, Workflows
from fastagency.api.openapi.client import OpenAPI
from fastagency.api.openapi.security import APIKeyQuery
from fastagency.base import MultipleChoice
from fastagency.runtime.autogen.base import AutoGenWorkflows
from fastagency.ui.mesop import MesopUI


open_api_key = os.getenv("OPENAI_API_KEY")
llm_config = {
"config_list": [
{
"model": "gpt-4o-mini",
"api_key": os.getenv("OPENAI_API_KEY"),
"api_key": open_api_key,
}
],
"temperature": 0.0,
}

openapi_url = "https://raw.githubusercontent.com/airtai/fastagency/refs/heads/main/examples/openapi/giphy_openapi.json"
giphy_api = OpenAPI.create(openapi_url=openapi_url)

giphy_api_key = os.getenv("GIPHY_API_KEY")
openapi_url="https://raw.githubusercontent.com/airtai/fastagency/refs/heads/main/examples/openapi/giphy_openapi.json"
giphy_api = OpenAPI.create(openapi_url=openapi_url)
giphy_api.set_security_params(APIKeyQuery.Parameters(value=giphy_api_key))

wf = AutoGenWorkflows()

wf = AutoGenWorkflows()

@wf.register(name="giphy_and_websurfer", description="Giphy and Websurfer chat")
def giphy_workflow_with_security(
@wf.register(name="giphy_chat", description="Giphy chat")
def giphy_workflow(
wf: Workflows, ui: UI, initial_message: str, session_id: str
) -> str:
def is_termination_msg(msg: dict[str, Any]) -> bool:
Expand All @@ -44,13 +41,18 @@ def is_termination_msg(msg: dict[str, Any]) -> bool:
is_termination_msg=is_termination_msg,
)

system_message="""You are a helper agent that communicates with the user and
Giphy API. When using API calls, always limit the response size to 5 items.
When finished, write 'TERMINATE' to end the conversation."""

giphy_agent = ConversableAgent(
name="Giphy_Agent",
system_message="You are a helper agent that communicates with the user and Giphy API. When using API, always limit the response size to 5 items. Write 'TERMINATE' to end the conversation.",
system_message=system_message,
llm_config=llm_config,
human_input_mode="NEVER",
is_termination_msg=is_termination_msg,
)

wf.register_api(
api=giphy_api,
callers=giphy_agent,
Expand Down
2 changes: 1 addition & 1 deletion fastagency/__about__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""The fastest way to bring multi-agent workflows to production."""

__version__ = "0.2.0rc1"
__version__ = "0.2.0rc2"
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mesop = [

pyautogen = [
"pyautogen[anthropic,together]>=0.2.35,<0.3",
"together==1.2.11",
"together==1.3.0",
]

autogen = [
Expand Down Expand Up @@ -87,16 +87,16 @@ server = [
# dev dependencies
devdocs = [
"mkdocs==1.6.1",
"mkdocs-autorefs==1.1.0", # mkdocs build fails if upgraded
"mkdocs-autorefs==1.2.0", # mkdocs build fails if upgraded
"mkdocs-material==9.5.33",
"mkdocs-static-i18n==1.2.3",
"mdx-include==1.4.2",
"mkdocstrings[python]==0.25.2",
"mkdocstrings[python]==0.26.1",
"mkdocs-literate-nav==0.6.1",
"mkdocs-git-revision-date-localized-plugin==1.2.9",
"mike==2.1.3", # versioning
"mkdocs-minify-plugin==0.8.0",
"mkdocs-macros-plugin==1.0.5", # includes with variables
"mkdocs-macros-plugin==1.2.0", # includes with variables
"mkdocs-glightbox==0.4.0", # img zoom
"pillow==10.4.0",
"cairosvg==2.7.1",
Expand All @@ -109,7 +109,7 @@ lint = [
"types-Pygments",
"types-docutils",
"mypy==1.11.2",
"ruff==0.6.5",
"ruff==0.6.8",
"pyupgrade-directories==0.3.0",
"bandit==1.7.9",
"semgrep==1.89.0",
Expand Down

0 comments on commit 35d37d2

Please sign in to comment.