-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa03525
commit 23b57c2
Showing
3 changed files
with
192 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
docs/docs_src/user_guide/runtime/autogen/websurfer_tool.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import os | ||
|
||
from autogen import UserProxyAgent | ||
from autogen.agentchat import ConversableAgent | ||
|
||
from fastagency import UI, FastAgency | ||
from fastagency.runtime.autogen import AutoGenWorkflows | ||
from fastagency.runtime.autogen.tools import WebSurferTool | ||
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_websurfer", description="WebSurfer chat") # type: ignore[type-var] | ||
def websurfer_workflow( | ||
wf: AutoGenWorkflows, ui: UI, initial_message: str, session_id: str | ||
) -> str: | ||
user_agent = UserProxyAgent( | ||
name="User_Agent", | ||
system_message="You are a user agent", | ||
llm_config=llm_config, | ||
human_input_mode="NEVER", | ||
) | ||
assistant_agent = ConversableAgent( | ||
name="Assistant_Agent", | ||
system_message="You are a useful assistant", | ||
llm_config=llm_config, | ||
human_input_mode="NEVER", | ||
) | ||
|
||
web_surfer = WebSurferTool( | ||
name_prefix="Web_Surfer", | ||
llm_config=llm_config, | ||
summarizer_llm_config=llm_config, | ||
) | ||
|
||
web_surfer.register( | ||
caller=assistant_agent, | ||
executor=user_agent, | ||
) | ||
|
||
chat_result = user_agent.initiate_chat( | ||
assistant_agent, | ||
message=initial_message, | ||
summary_method="reflection_with_llm", | ||
max_turns=3, | ||
) | ||
|
||
return chat_result.summary # type: ignore[no-any-return] | ||
|
||
|
||
app = FastAgency(wf=wf, ui=ConsoleUI()) |
28 changes: 28 additions & 0 deletions
28
tests/docs_src/user_guide/runtime/autogen/test_websurfer_tool.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pytest | ||
from typer.testing import CliRunner | ||
|
||
from fastagency.cli import app | ||
from tests.conftest import InputMock | ||
|
||
runner = CliRunner() | ||
|
||
INPUT_MESSAGE = ( | ||
"Search for information about Microsoft AutoGen and summarize the results," | ||
) | ||
|
||
|
||
@pytest.mark.openai | ||
def test_main(monkeypatch: pytest.MonkeyPatch) -> None: | ||
monkeypatch.setattr("builtins.input", InputMock([INPUT_MESSAGE])) | ||
|
||
result = runner.invoke( | ||
app, | ||
[ | ||
"run", | ||
"docs/docs_src/user_guide/runtime/autogen/websurfer_tool.py", | ||
"--single-run", | ||
], | ||
) | ||
assert result.exit_code == 0 | ||
# assert INPUT_MESSAGE in result.stdout | ||
assert "workflow -> user [workflow_completed]" in result.stdout |