Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
davorrunje committed Oct 9, 2024
1 parent d60bd81 commit 3809eab
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 9 deletions.
9 changes: 8 additions & 1 deletion docs/docs_src/user_guide/custom_user_interactions/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, param: dict[str, Any]) -> str:
initial_message = ui.text_input(
sender="Workflow",
recipient="User",
prompt="What do you want to learn today?",
workflow_id=workflow_uuid,
)

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

Expand Down
9 changes: 8 additions & 1 deletion docs/docs_src/user_guide/external_rest_apis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_id=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/external_rest_apis/security.py
Original file line number Diff line number Diff line change
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_id=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/ui/mesop/main_mesop.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from typing import Any

import mesop as me
from autogen.agentchat import ConversableAgent
Expand Down Expand Up @@ -27,8 +28,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="What do you want to learn today?",
workflow_id=workflow_uuid,
)

student_agent = ConversableAgent(
name="Student_Agent",
system_message="You are a student willing to learn.",
Expand Down
20 changes: 18 additions & 2 deletions fastagency/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,31 @@ async def handle_asgi(
) -> None: ...


Workflow = TypeVar("Workflow", bound=Callable[["WorkflowsProtocol", UI, str, str], str])
# signature of a function decorated with @wf.register
# Workflow = TypeVar("Workflow", bound=Callable[["WorkflowsProtocol", UI, str, str], str])
# parameters are: WorkflowsProtocol, UI, workflow_uuid, params (kwargs)
Workflow = TypeVar("Workflow", bound=Callable[[UI, str, dict[str, Any]], str])


Agent = TypeVar("Agent")


@runtime_checkable
class ProviderProtocol(Protocol):
def run(self, name: str, session_id: str, ui: UI, initial_message: str) -> str: ...
# def run(self, name: str, session_id: str, ui: UI, initial_message: str) -> str: ...
def run(self, name: str, ui: UI, **kwargs: Any) -> str: ...

"""Run a workflow.
Creates a new workflow and assigns it workflow_uuid. Then it calls the
workflow function (function decorated with @wf.register) with the given
ui and workflow_uuid.
Args:
name (str): The name of the workflow to run.
ui (UI): The UI object to use.
**kwargs: Additional parameters to pass to the workflow function.
"""

@property
def names(self) -> list[str]: ...
Expand Down
9 changes: 6 additions & 3 deletions fastagency/runtimes/autogen/autogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Union,
runtime_checkable,
)
from uuid import uuid4

from autogen.agentchat import ConversableAgent
from autogen.io import IOStream
Expand Down Expand Up @@ -270,7 +271,7 @@ class AutoGenWorkflows(WorkflowsProtocol):
def __init__(self) -> None:
"""Initialize the workflows."""
self._workflows: dict[
str, tuple[Callable[[WorkflowsProtocol, UI, str, str], str], str]
str, tuple[Callable[[UI, str, dict[str, Any]], str], str]
] = {}

def register(
Expand All @@ -288,13 +289,15 @@ def decorator(func: Workflow) -> Workflow:

return decorator

def run(self, name: str, session_id: str, ui: UI, initial_message: str) -> str:
# def run(self, name: str, session_id: str, ui: UI, initial_message: str) -> str:
def run(self, name: str, ui: UI, **kwargs: Any) -> str:
workflow, description = self._workflows[name]

iostream = IOStreamAdapter(ui)

workflow_uuid = uuid4().hex
with IOStream.set_default(iostream):
return workflow(self, ui, initial_message, session_id)
return workflow(ui, workflow_uuid, kwargs)

@property
def names(self) -> list[str]:
Expand Down

0 comments on commit 3809eab

Please sign in to comment.