Skip to content

Commit

Permalink
Refactor workflow run (#355)
Browse files Browse the repository at this point in the history
* wip

* fixing the user_proxy worklow

* fixing the giffy docs

* fixing the gifmesop docs

* fixing the console example

* fxings tests to pass mypy (they would probably still fail

* fixed the main_mesop example

* Update nats and fastapi providers to support new run method signature

* Run pre-commit

* fix examples main_console.py

* mesop no longer asks for initial message

* figure out suitable conversation name in mesop

* mesop selector for available workflows

* wip

* import tests added for docs_src and examples

* import tests added for docs_src and examples

* test fix

* test fix in 3.9

* add no-llm tests into pre-commit hook

* test fix

---------

Co-authored-by: Davorin Rusevljan <davorin.rusevljan@gmail.com>
Co-authored-by: Kumaran Rajendhiran <kumaran@airt.ai>
  • Loading branch information
3 people authored Oct 9, 2024
1 parent 23c1a47 commit ea67172
Show file tree
Hide file tree
Showing 47 changed files with 633 additions and 303 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ jobs:
pre-commit-check:
runs-on: ubuntu-latest
env:
SKIP: "static-analysis"
SKIP: "static-analysis, test"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand Down
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ repos:
require_serial: true
verbose: true

- repo: local
hooks:
- id: test
name: Test
entry: "scripts/test-no-llm-pre-commit.sh"
language: python
# language_version: python3.9
types: [python]
require_serial: true
verbose: true

- repo: local
hooks:
- id: static-analysis
Expand Down
8 changes: 6 additions & 2 deletions docs/docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ search:
- base
- [FastAPIAdapter](api/fastagency/adapters/fastapi/base/FastAPIAdapter.md)
- [FastAPIProvider](api/fastagency/adapters/fastapi/base/FastAPIProvider.md)
- [InititateChatModel](api/fastagency/adapters/fastapi/base/InititateChatModel.md)
- [WorkflowInfo](api/fastagency/adapters/fastapi/base/WorkflowInfo.md)
- nats
- [InitiateModel](api/fastagency/adapters/nats/InitiateModel.md)
- [InitiateWorkflowModel](api/fastagency/adapters/nats/InitiateWorkflowModel.md)
- [InputResponseModel](api/fastagency/adapters/nats/InputResponseModel.md)
- [NatsAdapter](api/fastagency/adapters/nats/NatsAdapter.md)
- [NatsProvider](api/fastagency/adapters/nats/NatsProvider.md)
- base
- [InitiateModel](api/fastagency/adapters/nats/base/InitiateModel.md)
- [InitiateWorkflowModel](api/fastagency/adapters/nats/base/InitiateWorkflowModel.md)
- [InputResponseModel](api/fastagency/adapters/nats/base/InputResponseModel.md)
- [NatsAdapter](api/fastagency/adapters/nats/base/NatsAdapter.md)
- [NatsProvider](api/fastagency/adapters/nats/base/NatsProvider.md)
Expand Down Expand Up @@ -80,6 +82,7 @@ search:
- [UI](api/fastagency/base/UI.md)
- [WSGIProtocol](api/fastagency/base/WSGIProtocol.md)
- [WorkflowsProtocol](api/fastagency/base/WorkflowsProtocol.md)
- [check_register_decorator](api/fastagency/base/check_register_decorator.md)
- [run_workflow](api/fastagency/base/run_workflow.md)
- cli
- cli
Expand Down Expand Up @@ -170,6 +173,7 @@ search:
- message
- [MesopGUIMessageVisitor](api/fastagency/ui/mesop/message/MesopGUIMessageVisitor.md)
- [consume_responses](api/fastagency/ui/mesop/message/consume_responses.md)
- [find_suitable_title](api/fastagency/ui/mesop/message/find_suitable_title.md)
- [handle_message](api/fastagency/ui/mesop/message/handle_message.md)
- [message_box](api/fastagency/ui/mesop/message/message_box.md)
- send_prompt
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 0.5
---

::: fastagency.adapters.fastapi.base.InititateChatModel
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.adapters.nats.base.InitiateModel
::: fastagency.adapters.fastapi.base.WorkflowInfo
11 changes: 11 additions & 0 deletions docs/docs/en/api/fastagency/adapters/nats/InitiateWorkflowModel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 0.5
---

::: fastagency.adapters.nats.InitiateWorkflowModel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 0.5
---

::: fastagency.adapters.nats.base.InitiateWorkflowModel
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.adapters.nats.InitiateModel
::: fastagency.base.check_register_decorator
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 0.5
---

::: fastagency.ui.mesop.message.find_suitable_title
2 changes: 0 additions & 2 deletions docs/docs/en/cli/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ $ fastagency dev [OPTIONS] [PATH]

* `--app TEXT`: The name of the variable that contains the **** app in the imported module or package. If not provided, it is detected automatically.
* `-w, --workflow TEXT`: The name of the workflow to run. If not provided, the default workflow will be run.
* `-i, --initial_message TEXT`: The initial message to send to the workflow. If not provided, a default message will be sent.
* `--single-run`: If set, only a single workflow will be executed.
* `--help`: Show this message and exit.

Expand Down Expand Up @@ -107,7 +106,6 @@ $ fastagency run [OPTIONS] [PATH]

* `--app TEXT`: The name of the variable that contains the **** app in the imported module or package. If not provided, it is detected automatically.
* `-w, --workflow TEXT`: The name of the workflow to run. If not provided, the default workflow will be run.
* `-i, --initial_message TEXT`: The initial message to send to the workflow. If not provided, a default message will be sent.
* `--single-run`: If set, only a single workflow will be executed.
* `--help`: Show this message and exit.

Expand Down
12 changes: 10 additions & 2 deletions docs/docs_src/getting_started/main_console.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
from typing import Any

from autogen.agentchat import ConversableAgent

from fastagency import UI, FastAgency, WorkflowsProtocol
from fastagency import UI, FastAgency
from fastagency.runtimes.autogen import AutoGenWorkflows
from fastagency.ui.console import ConsoleUI

Expand All @@ -21,8 +22,15 @@

@wf.register(name="simple_learning", description="Student and teacher learning chat")
def simple_workflow(
wf: WorkflowsProtocol, ui: UI, initial_message: str, session_id: str
ui: UI, workflow_uuid: str, params: dict[str, Any]
) -> str:
initial_message = ui.text_input(
sender="Workflow",
recipient="User",
prompt="I can help you learn about geometry. What subject you would like to explore?",
workflow_uuid=workflow_uuid,
)

student_agent = ConversableAgent(
name="Student_Agent",
system_message="You are a student willing to learn.",
Expand Down
12 changes: 10 additions & 2 deletions docs/docs_src/getting_started/main_mesop.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
from typing import Any

from autogen.agentchat import ConversableAgent

from fastagency import UI, FastAgency, WorkflowsProtocol
from fastagency import UI, FastAgency
from fastagency.runtimes.autogen import AutoGenWorkflows
from fastagency.ui.mesop import MesopUI

Expand All @@ -21,8 +22,15 @@

@wf.register(name="simple_learning", description="Student and teacher learning chat")
def simple_workflow(
wf: WorkflowsProtocol, ui: UI, initial_message: str, session_id: str
ui: UI, workflow_uuid: str, params: dict[str, Any]
) -> str:
initial_message = ui.text_input(
sender="Workflow",
recipient="User",
prompt="I can help you learn about geometry. What subject you would like to explore?",
workflow_uuid=workflow_uuid,
)

student_agent = ConversableAgent(
name="Student_Agent",
system_message="You are a student willing to learn.",
Expand Down
13 changes: 10 additions & 3 deletions docs/docs_src/tutorial/giphy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from autogen import register_function
from autogen.agentchat import ConversableAgent

from fastagency import UI, FastAgency, WorkflowsProtocol
from fastagency import UI, FastAgency
from fastagency.api.openapi.client import OpenAPI
from fastagency.api.openapi.security import APIKeyQuery
from fastagency.messages import TextInput
Expand All @@ -25,7 +25,7 @@
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")
giphy_api_key = os.getenv("GIPHY_API_KEY", "")
giphy_api.set_security_params(APIKeyQuery.Parameters(value=giphy_api_key))

GIPHY_SYSTEM_MESSAGE = """You are an agent in charge to communicate with the user and Giphy API.
Expand Down Expand Up @@ -57,7 +57,7 @@

@wf.register(name="giphy_and_websurfer", description="Giphy and Websurfer chat")
def giphy_workflow_with_security(
wf: WorkflowsProtocol, ui: UI, initial_message: str, session_id: str
ui: UI, workflow_uuid: str, params: dict[str, Any]
) -> str:
def is_termination_msg(msg: dict[str, Any]) -> bool:
return msg["content"] is not None and "TERMINATE" in msg["content"]
Expand Down Expand Up @@ -108,6 +108,13 @@ def present_completed_task_or_ask_question(
functions=functions,
)

initial_message = ui.text_input(
sender="Workflow",
recipient="User",
prompt="I can help you find images related to a certain subject. What kind of images would you like to find?",
workflow_uuid=workflow_uuid,
)

chat_result = giphy_agent.initiate_chat(
web_surfer,
message=f"Users initial message: {initial_message}",
Expand Down
13 changes: 10 additions & 3 deletions docs/docs_src/tutorial/giphy/simple_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from autogen import ConversableAgent, UserProxyAgent

from fastagency import UI, FastAgency, WorkflowsProtocol
from fastagency import UI, FastAgency
from fastagency.api.openapi.client import OpenAPI
from fastagency.api.openapi.security import APIKeyQuery
from fastagency.runtimes.autogen.autogen import AutoGenWorkflows
Expand All @@ -20,7 +20,7 @@
"temperature": 0.0,
}

giphy_api_key = os.getenv("GIPHY_API_KEY")
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))
Expand All @@ -30,7 +30,7 @@

@wf.register(name="giphy_chat", description="Giphy chat")
def giphy_workflow(
wf: WorkflowsProtocol, ui: UI, initial_message: str, session_id: str
ui: UI, workflow_uuid: str, params: dict[str, Any]
) -> str:
def is_termination_msg(msg: dict[str, Any]) -> bool:
return msg["content"] is not None and "TERMINATE" in msg["content"]
Expand Down Expand Up @@ -60,6 +60,13 @@ def is_termination_msg(msg: dict[str, Any]) -> bool:
functions=["random_gif", "search_gifs", "trending_gifs"],
)

initial_message = ui.text_input(
sender="Workflow",
recipient="User",
prompt="I can help you find images related to a certain subject. What kind of images would you like to find?",
workflow_uuid=workflow_uuid,
)

chat_result = user_proxy.initiate_chat(
giphy_agent,
message=initial_message,
Expand Down
11 changes: 9 additions & 2 deletions docs/docs_src/user_guide/custom_user_interactions/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from autogen import register_function
from autogen.agentchat import ConversableAgent

from fastagency import UI, FastAgency, WorkflowsProtocol
from fastagency import UI, FastAgency
from fastagency.messages import MultipleChoice, SystemMessage, TextInput
from fastagency.runtimes.autogen.autogen import AutoGenWorkflows
from fastagency.ui.console import ConsoleUI
Expand All @@ -23,7 +23,14 @@


@wf.register(name="exam_practice", description="Student and teacher chat")
def exam_learning(wf: WorkflowsProtocol, ui: UI, initial_message: str, session_id: str) -> str:
def exam_learning(ui: UI, workflow_uuid: str, params: dict[str, Any]) -> str:
initial_message = ui.text_input(
sender="Workflow",
recipient="User",
prompt="What do you want to learn today?",
workflow_uuid=workflow_uuid,
)

def is_termination_msg(msg: dict[str, Any]) -> bool:
return msg["content"] is not None and "TERMINATE" in msg["content"]

Expand Down
11 changes: 9 additions & 2 deletions docs/docs_src/user_guide/external_rest_apis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from autogen import UserProxyAgent
from autogen.agentchat import ConversableAgent

from fastagency import UI, FastAgency, WorkflowsProtocol
from fastagency import UI, FastAgency
from fastagency.api.openapi import OpenAPI
from fastagency.runtimes.autogen.autogen import AutoGenWorkflows
from fastagency.ui.console import ConsoleUI
Expand All @@ -26,8 +26,15 @@

@wf.register(name="simple_weather", description="Weather chat")
def weather_workflow(
wf: WorkflowsProtocol, ui: UI, initial_message: str, session_id: str
ui: UI, workflow_uuid: str, params: dict[str, str]
) -> str:
initial_message = ui.text_input(
sender="Workflow",
recipient="User",
prompt="What do you want to know about the weather?",
workflow_uuid=workflow_uuid,
)

user_agent = UserProxyAgent(
name="User_Agent",
system_message="You are a user agent",
Expand Down
11 changes: 9 additions & 2 deletions docs/docs_src/user_guide/external_rest_apis/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from autogen import UserProxyAgent
from autogen.agentchat import ConversableAgent

from fastagency import UI, FastAgency, WorkflowsProtocol
from fastagency import UI, FastAgency
from fastagency.api.openapi.client import OpenAPI
from fastagency.api.openapi.security import APIKeyHeader
from fastagency.runtimes.autogen.autogen import AutoGenWorkflows
Expand Down Expand Up @@ -38,8 +38,15 @@
name="simple_weather_with_security", description="Weather chat with security"
)
def weather_workflow_with_security(
wf: WorkflowsProtocol, ui: UI, initial_message: str, session_id: str
ui: UI, workflow_uuid: str, params: dict[str, str]
) -> str:
initial_message = ui.text_input(
sender="Workflow",
recipient="User",
prompt="What do you want to know about the weather?",
workflow_uuid=workflow_uuid,
)

user_agent = UserProxyAgent(
name="User_Agent",
system_message="You are a user agent",
Expand Down
10 changes: 9 additions & 1 deletion docs/docs_src/user_guide/runtimes/autogen/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from typing import Any

from autogen import UserProxyAgent
from autogen.agentchat import ConversableAgent
Expand Down Expand Up @@ -27,8 +28,15 @@

@wf.register(name="simple_weather", description="Weather chat") # type: ignore[type-var]
def weather_workflow(
wf: AutoGenWorkflows, ui: UI, initial_message: str, session_id: str
ui: UI, workflow_uuid: str, params: dict[str, Any]
) -> str:
initial_message = ui.text_input(
sender="Workflow",
recipient="User",
prompt="I can help you with the weather. What would you like to know?",
workflow_uuid=workflow_uuid,
)

user_agent = UserProxyAgent(
name="User_Agent",
system_message="You are a user agent",
Expand Down
9 changes: 8 additions & 1 deletion docs/docs_src/user_guide/runtimes/autogen/websurfer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from typing import Any

from autogen import UserProxyAgent

Expand All @@ -21,8 +22,14 @@

@wf.register(name="simple_websurfer", description="WebSurfer chat") # type: ignore[type-var]
def websurfer_workflow(
wf: AutoGenWorkflows, ui: UI, initial_message: str, session_id: str
ui: UI, workflow_uuid: str, params: dict[str, Any]
) -> str:
initial_message = ui.text_input(
sender="Workflow",
recipient="User",
prompt="I can help you with your web search. What would you like to know?",
workflow_uuid=workflow_uuid,
)
user_agent = UserProxyAgent(
name="User_Agent",
system_message="You are a user agent",
Expand Down
Loading

0 comments on commit ea67172

Please sign in to comment.