Skip to content

Commit

Permalink
Mesop app created in the same process (#193)
Browse files Browse the repository at this point in the history
* Mesop app is created in the same process

* bug fix

* fixed examples

* test fix
  • Loading branch information
davorrunje authored Sep 12, 2024
1 parent 8b072f3 commit a58ab7b
Show file tree
Hide file tree
Showing 23 changed files with 178 additions and 148 deletions.
6 changes: 3 additions & 3 deletions docs/docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ search:
- [Custom User Interactions](tutorial/custom-user-interactions/index.md)
- Reference
- fastagency
- [Chatable](api/fastagency/Chatable.md)
- [FastAgency](api/fastagency/FastAgency.md)
- [FunctionCallExecution](api/fastagency/FunctionCallExecution.md)
- [IOMessage](api/fastagency/IOMessage.md)
- [MultipleChoice](api/fastagency/MultipleChoice.md)
- [SuggestedFunctionCall](api/fastagency/SuggestedFunctionCall.md)
- [TextInput](api/fastagency/TextInput.md)
- [TextMessage](api/fastagency/TextMessage.md)
- [UI](api/fastagency/UI.md)
- [Workflows](api/fastagency/Workflows.md)
- api
- openapi
Expand All @@ -42,7 +42,6 @@ search:
- [FastAgency](api/fastagency/app/FastAgency.md)
- base
- [AskingMessage](api/fastagency/base/AskingMessage.md)
- [Chatable](api/fastagency/base/Chatable.md)
- [FunctionCallExecution](api/fastagency/base/FunctionCallExecution.md)
- [IOMessage](api/fastagency/base/IOMessage.md)
- [IOMessageVisitor](api/fastagency/base/IOMessageVisitor.md)
Expand All @@ -52,6 +51,7 @@ search:
- [SystemMessage](api/fastagency/base/SystemMessage.md)
- [TextInput](api/fastagency/base/TextInput.md)
- [TextMessage](api/fastagency/base/TextMessage.md)
- [UI](api/fastagency/base/UI.md)
- [WorkflowCompleted](api/fastagency/base/WorkflowCompleted.md)
- [Workflows](api/fastagency/base/Workflows.md)
- [run_workflow](api/fastagency/base/run_workflow.md)
Expand Down Expand Up @@ -251,7 +251,7 @@ search:
- main
- [conversation_box](api/fastagency/ui/mesop/main/conversation_box.md)
- [conversation_starter_box](api/fastagency/ui/mesop/main/conversation_starter_box.md)
- [get_workflows](api/fastagency/ui/mesop/main/get_workflows.md)
- [get_ui](api/fastagency/ui/mesop/main/get_ui.md)
- [home_page](api/fastagency/ui/mesop/main/home_page.md)
- [on_user_feedback](api/fastagency/ui/mesop/main/on_user_feedback.md)
- [past_conversations_box](api/fastagency/ui/mesop/main/past_conversations_box.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.Chatable
::: fastagency.UI
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

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

::: fastagency.ui.mesop.main.get_workflows
::: fastagency.ui.mesop.main.get_ui
6 changes: 3 additions & 3 deletions docs/docs_src/tutorial/custom_user_interactions/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from autogen.agentchat import ConversableAgent

from fastagency import FastAgency
from fastagency import Chatable
from fastagency import UI
from fastagency.base import MultipleChoice, SystemMessage, TextInput
from fastagency.ui.console import ConsoleUI
from fastagency.runtimes.autogen.base import AutoGenWorkflows
Expand All @@ -24,7 +24,7 @@


@wf.register(name="exam_practice", description="Student and teacher chat") # type: ignore[type-var]
def exam_learning(io: Chatable, initial_message: str, session_id: str) -> Optional[str]:
def exam_learning(io: UI, initial_message: str, session_id: str) -> Optional[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 @@ -132,4 +132,4 @@ def get_final_grade(
return chat_result.summary # type: ignore[no-any-return]


app = FastAgency(wf=wf, io=ConsoleUI())
app = FastAgency(wf=wf, ui=ConsoleUI())
6 changes: 3 additions & 3 deletions docs/docs_src/tutorial/external_rest_apis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from autogen.agentchat import ConversableAgent

from fastagency import FastAgency
from fastagency import Chatable
from fastagency import UI
from fastagency.ui.console import ConsoleUI
from fastagency.runtimes.autogen.base import AutoGenWorkflows

Expand All @@ -27,7 +27,7 @@


@wf.register(name="simple_weather", description="Weather chat")
def weather_workflow(io: Chatable, initial_message: str, session_id: str) -> str:
def weather_workflow(io: UI, initial_message: str, session_id: str) -> str:

weather_api = OpenAPI.create(openapi_url=WEATHER_OPENAPI_URL)

Expand Down Expand Up @@ -57,4 +57,4 @@ def weather_workflow(io: Chatable, initial_message: str, session_id: str) -> str
return chat_result.summary # type: ignore[no-any-return]


app = FastAgency(wf=wf, io=ConsoleUI())
app = FastAgency(wf=wf, ui=ConsoleUI())
6 changes: 3 additions & 3 deletions docs/docs_src/tutorial/external_rest_apis/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from autogen.agentchat import ConversableAgent

from fastagency import FastAgency
from fastagency import Chatable
from fastagency import UI
from fastagency.ui.console import ConsoleUI
from fastagency.runtimes.autogen.base import AutoGenWorkflows
from fastagency.api.openapi.client import OpenAPI
Expand All @@ -26,7 +26,7 @@


@wf.register(name="simple_weather_with_security", description="Weather chat with security")
def weather_workflow_with_security(io: Chatable, initial_message: str, session_id: str) -> str:
def weather_workflow_with_security(io: UI, initial_message: str, session_id: str) -> str:

weather_client = OpenAPI.create(openapi_url=WEATHER_OPENAPI_URL)

Expand Down Expand Up @@ -65,4 +65,4 @@ def weather_workflow_with_security(io: Chatable, initial_message: str, session_i
return chat_result.summary # type: ignore[no-any-return]


app = FastAgency(wf=wf, io=ConsoleUI())
app = FastAgency(wf=wf, ui=ConsoleUI())
6 changes: 3 additions & 3 deletions docs/docs_src/tutorial/getting_started/main.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 FastAgency
from fastagency import Chatable
from fastagency import UI
from fastagency.ui.console import ConsoleUI
from fastagency.runtimes.autogen.base import AutoGenWorkflows

Expand All @@ -21,7 +21,7 @@


@wf.register(name="simple_learning", description="Student and teacher learning chat")
def simple_workflow(io: Chatable, initial_message: str, session_id: str) -> str:
def simple_workflow(io: 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 @@ -44,4 +44,4 @@ def simple_workflow(io: Chatable, initial_message: str, session_id: str) -> str:



app = FastAgency(wf=wf, io=ConsoleUI())
app = FastAgency(wf=wf, ui=ConsoleUI())
6 changes: 3 additions & 3 deletions examples/cli/main_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from autogen.agentchat import ConversableAgent

from fastagency import Chatable
from fastagency import UI
from fastagency.ui.console import ConsoleUI
from fastagency.runtimes.autogen.base import AutoGenWorkflows

Expand All @@ -22,7 +22,7 @@
wf = AutoGenWorkflows()

@wf.register(name="simple_learning", description="Student and teacher learning chat")
def simple_workflow(io: Chatable, initial_message: str, session_id: str) -> str:
def simple_workflow(io: 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 @@ -43,4 +43,4 @@ def simple_workflow(io: Chatable, initial_message: str, session_id: str) -> str:

return chat_result.summary

app = FastAgency(wf=wf, io=ConsoleUI())
app = FastAgency(wf=wf, ui=ConsoleUI())
6 changes: 3 additions & 3 deletions examples/cli/main_mesop.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from autogen.agentchat import ConversableAgent

from fastagency import Chatable
from fastagency import UI
from fastagency.ui.mesop import MesopUI
from fastagency.runtimes.autogen.base import AutoGenWorkflows

Expand All @@ -22,7 +22,7 @@
wf = AutoGenWorkflows()

@wf.register(name="simple_learning", description="Student and teacher learning chat")
def simple_workflow(io: Chatable, initial_message: str, session_id: str) -> str:
def simple_workflow(io: 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 @@ -43,4 +43,4 @@ def simple_workflow(io: Chatable, initial_message: str, session_id: str) -> str:

return chat_result.summary

app = FastAgency(wf=wf, io=MesopUI())
app = FastAgency(wf=wf, ui=MesopUI())
6 changes: 3 additions & 3 deletions examples/cli/main_user_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from autogen.agentchat import ConversableAgent, UserProxyAgent

from fastagency import Chatable
from fastagency import UI
from fastagency.ui.console import ConsoleUI
from fastagency.runtimes.autogen.base import AutoGenWorkflows
from fastagency.api.openapi.client import OpenAPI
Expand All @@ -24,7 +24,7 @@
wf = AutoGenWorkflows()

@wf.register(name="weatherman_workflow", description="Weatherman chat")
def simple_workflow(io: Chatable, initial_message: str, session_id: str) -> str:
def simple_workflow(io: UI, initial_message: str, session_id: str) -> str:

user_proxy = UserProxyAgent(
name="User_Proxy",
Expand Down Expand Up @@ -52,4 +52,4 @@ def simple_workflow(io: Chatable, initial_message: str, session_id: str) -> str:

return chat_result.summary

app = FastAgency(wf=wf, io=ConsoleUI())
app = FastAgency(wf=wf, ui=ConsoleUI())
4 changes: 2 additions & 2 deletions fastagency/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .__about__ import __version__
from .app import FastAgency
from .base import (
Chatable,
UI,
FunctionCallExecution,
IOMessage,
MessageType,
Expand All @@ -16,7 +16,7 @@
)

__all__ = [
"Chatable",
"UI",
"FastAgency",
"FunctionCallExecution",
"IOMessage",
Expand Down
24 changes: 14 additions & 10 deletions fastagency/app.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
__all__ = ["FastAgency"]

from collections.abc import Generator
from contextlib import contextmanager
from typing import Optional

from .base import Chatable, Workflows
from .base import UI, Workflows


class FastAgency: # Runnable
def __init__(self, wf: Workflows, io: Chatable) -> None:
def __init__(self, wf: Workflows, ui: UI) -> None:
"""Initialize the FastAgency object.
Args:
wf (Workflows): The workflows object to use
io (Chatable): The IO object to use
ui (Chatable): The UI object to use
"""
self._wf = wf
self._io = io
self._ui = ui

@property
def wf(self) -> Workflows:
"""Return the workflows object."""
return self._wf

@property
def io(self) -> Chatable:
"""Return the IO object."""
return self._io
def ui(self) -> UI:
"""Return the UI object."""
return self._ui

def create(self, import_string: str) -> None:
@contextmanager
def create(self, import_string: str) -> Generator[None, None, None]:
"""Create the FastAgency."""
self._io.create(app=self, import_string=import_string)
with self._ui.create(app=self, import_string=import_string):
yield

def start(
self,
Expand All @@ -37,7 +41,7 @@ def start(
initial_message: Optional[str] = None,
) -> None:
"""Start the FastAgency."""
self._io.start(
self.ui.start(
app=self,
import_string=import_string,
name=name,
Expand Down
Loading

0 comments on commit a58ab7b

Please sign in to comment.