fast-agent-mcp 0.4.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fast_agent/__init__.py +183 -0
- fast_agent/acp/__init__.py +19 -0
- fast_agent/acp/acp_aware_mixin.py +304 -0
- fast_agent/acp/acp_context.py +437 -0
- fast_agent/acp/content_conversion.py +136 -0
- fast_agent/acp/filesystem_runtime.py +427 -0
- fast_agent/acp/permission_store.py +269 -0
- fast_agent/acp/server/__init__.py +5 -0
- fast_agent/acp/server/agent_acp_server.py +1472 -0
- fast_agent/acp/slash_commands.py +1050 -0
- fast_agent/acp/terminal_runtime.py +408 -0
- fast_agent/acp/tool_permission_adapter.py +125 -0
- fast_agent/acp/tool_permissions.py +474 -0
- fast_agent/acp/tool_progress.py +814 -0
- fast_agent/agents/__init__.py +85 -0
- fast_agent/agents/agent_types.py +64 -0
- fast_agent/agents/llm_agent.py +350 -0
- fast_agent/agents/llm_decorator.py +1139 -0
- fast_agent/agents/mcp_agent.py +1337 -0
- fast_agent/agents/tool_agent.py +271 -0
- fast_agent/agents/workflow/agents_as_tools_agent.py +849 -0
- fast_agent/agents/workflow/chain_agent.py +212 -0
- fast_agent/agents/workflow/evaluator_optimizer.py +380 -0
- fast_agent/agents/workflow/iterative_planner.py +652 -0
- fast_agent/agents/workflow/maker_agent.py +379 -0
- fast_agent/agents/workflow/orchestrator_models.py +218 -0
- fast_agent/agents/workflow/orchestrator_prompts.py +248 -0
- fast_agent/agents/workflow/parallel_agent.py +250 -0
- fast_agent/agents/workflow/router_agent.py +353 -0
- fast_agent/cli/__init__.py +0 -0
- fast_agent/cli/__main__.py +73 -0
- fast_agent/cli/commands/acp.py +159 -0
- fast_agent/cli/commands/auth.py +404 -0
- fast_agent/cli/commands/check_config.py +783 -0
- fast_agent/cli/commands/go.py +514 -0
- fast_agent/cli/commands/quickstart.py +557 -0
- fast_agent/cli/commands/serve.py +143 -0
- fast_agent/cli/commands/server_helpers.py +114 -0
- fast_agent/cli/commands/setup.py +174 -0
- fast_agent/cli/commands/url_parser.py +190 -0
- fast_agent/cli/constants.py +40 -0
- fast_agent/cli/main.py +115 -0
- fast_agent/cli/terminal.py +24 -0
- fast_agent/config.py +798 -0
- fast_agent/constants.py +41 -0
- fast_agent/context.py +279 -0
- fast_agent/context_dependent.py +50 -0
- fast_agent/core/__init__.py +92 -0
- fast_agent/core/agent_app.py +448 -0
- fast_agent/core/core_app.py +137 -0
- fast_agent/core/direct_decorators.py +784 -0
- fast_agent/core/direct_factory.py +620 -0
- fast_agent/core/error_handling.py +27 -0
- fast_agent/core/exceptions.py +90 -0
- fast_agent/core/executor/__init__.py +0 -0
- fast_agent/core/executor/executor.py +280 -0
- fast_agent/core/executor/task_registry.py +32 -0
- fast_agent/core/executor/workflow_signal.py +324 -0
- fast_agent/core/fastagent.py +1186 -0
- fast_agent/core/logging/__init__.py +5 -0
- fast_agent/core/logging/events.py +138 -0
- fast_agent/core/logging/json_serializer.py +164 -0
- fast_agent/core/logging/listeners.py +309 -0
- fast_agent/core/logging/logger.py +278 -0
- fast_agent/core/logging/transport.py +481 -0
- fast_agent/core/prompt.py +9 -0
- fast_agent/core/prompt_templates.py +183 -0
- fast_agent/core/validation.py +326 -0
- fast_agent/event_progress.py +62 -0
- fast_agent/history/history_exporter.py +49 -0
- fast_agent/human_input/__init__.py +47 -0
- fast_agent/human_input/elicitation_handler.py +123 -0
- fast_agent/human_input/elicitation_state.py +33 -0
- fast_agent/human_input/form_elements.py +59 -0
- fast_agent/human_input/form_fields.py +256 -0
- fast_agent/human_input/simple_form.py +113 -0
- fast_agent/human_input/types.py +40 -0
- fast_agent/interfaces.py +310 -0
- fast_agent/llm/__init__.py +9 -0
- fast_agent/llm/cancellation.py +22 -0
- fast_agent/llm/fastagent_llm.py +931 -0
- fast_agent/llm/internal/passthrough.py +161 -0
- fast_agent/llm/internal/playback.py +129 -0
- fast_agent/llm/internal/silent.py +41 -0
- fast_agent/llm/internal/slow.py +38 -0
- fast_agent/llm/memory.py +275 -0
- fast_agent/llm/model_database.py +490 -0
- fast_agent/llm/model_factory.py +388 -0
- fast_agent/llm/model_info.py +102 -0
- fast_agent/llm/prompt_utils.py +155 -0
- fast_agent/llm/provider/anthropic/anthropic_utils.py +84 -0
- fast_agent/llm/provider/anthropic/cache_planner.py +56 -0
- fast_agent/llm/provider/anthropic/llm_anthropic.py +796 -0
- fast_agent/llm/provider/anthropic/multipart_converter_anthropic.py +462 -0
- fast_agent/llm/provider/bedrock/bedrock_utils.py +218 -0
- fast_agent/llm/provider/bedrock/llm_bedrock.py +2207 -0
- fast_agent/llm/provider/bedrock/multipart_converter_bedrock.py +84 -0
- fast_agent/llm/provider/google/google_converter.py +466 -0
- fast_agent/llm/provider/google/llm_google_native.py +681 -0
- fast_agent/llm/provider/openai/llm_aliyun.py +31 -0
- fast_agent/llm/provider/openai/llm_azure.py +143 -0
- fast_agent/llm/provider/openai/llm_deepseek.py +76 -0
- fast_agent/llm/provider/openai/llm_generic.py +35 -0
- fast_agent/llm/provider/openai/llm_google_oai.py +32 -0
- fast_agent/llm/provider/openai/llm_groq.py +42 -0
- fast_agent/llm/provider/openai/llm_huggingface.py +85 -0
- fast_agent/llm/provider/openai/llm_openai.py +1195 -0
- fast_agent/llm/provider/openai/llm_openai_compatible.py +138 -0
- fast_agent/llm/provider/openai/llm_openrouter.py +45 -0
- fast_agent/llm/provider/openai/llm_tensorzero_openai.py +128 -0
- fast_agent/llm/provider/openai/llm_xai.py +38 -0
- fast_agent/llm/provider/openai/multipart_converter_openai.py +561 -0
- fast_agent/llm/provider/openai/openai_multipart.py +169 -0
- fast_agent/llm/provider/openai/openai_utils.py +67 -0
- fast_agent/llm/provider/openai/responses.py +133 -0
- fast_agent/llm/provider_key_manager.py +139 -0
- fast_agent/llm/provider_types.py +34 -0
- fast_agent/llm/request_params.py +61 -0
- fast_agent/llm/sampling_converter.py +98 -0
- fast_agent/llm/stream_types.py +9 -0
- fast_agent/llm/usage_tracking.py +445 -0
- fast_agent/mcp/__init__.py +56 -0
- fast_agent/mcp/common.py +26 -0
- fast_agent/mcp/elicitation_factory.py +84 -0
- fast_agent/mcp/elicitation_handlers.py +164 -0
- fast_agent/mcp/gen_client.py +83 -0
- fast_agent/mcp/helpers/__init__.py +36 -0
- fast_agent/mcp/helpers/content_helpers.py +352 -0
- fast_agent/mcp/helpers/server_config_helpers.py +25 -0
- fast_agent/mcp/hf_auth.py +147 -0
- fast_agent/mcp/interfaces.py +92 -0
- fast_agent/mcp/logger_textio.py +108 -0
- fast_agent/mcp/mcp_agent_client_session.py +411 -0
- fast_agent/mcp/mcp_aggregator.py +2175 -0
- fast_agent/mcp/mcp_connection_manager.py +723 -0
- fast_agent/mcp/mcp_content.py +262 -0
- fast_agent/mcp/mime_utils.py +108 -0
- fast_agent/mcp/oauth_client.py +509 -0
- fast_agent/mcp/prompt.py +159 -0
- fast_agent/mcp/prompt_message_extended.py +155 -0
- fast_agent/mcp/prompt_render.py +84 -0
- fast_agent/mcp/prompt_serialization.py +580 -0
- fast_agent/mcp/prompts/__init__.py +0 -0
- fast_agent/mcp/prompts/__main__.py +7 -0
- fast_agent/mcp/prompts/prompt_constants.py +18 -0
- fast_agent/mcp/prompts/prompt_helpers.py +238 -0
- fast_agent/mcp/prompts/prompt_load.py +186 -0
- fast_agent/mcp/prompts/prompt_server.py +552 -0
- fast_agent/mcp/prompts/prompt_template.py +438 -0
- fast_agent/mcp/resource_utils.py +215 -0
- fast_agent/mcp/sampling.py +200 -0
- fast_agent/mcp/server/__init__.py +4 -0
- fast_agent/mcp/server/agent_server.py +613 -0
- fast_agent/mcp/skybridge.py +44 -0
- fast_agent/mcp/sse_tracking.py +287 -0
- fast_agent/mcp/stdio_tracking_simple.py +59 -0
- fast_agent/mcp/streamable_http_tracking.py +309 -0
- fast_agent/mcp/tool_execution_handler.py +137 -0
- fast_agent/mcp/tool_permission_handler.py +88 -0
- fast_agent/mcp/transport_tracking.py +634 -0
- fast_agent/mcp/types.py +24 -0
- fast_agent/mcp/ui_agent.py +48 -0
- fast_agent/mcp/ui_mixin.py +209 -0
- fast_agent/mcp_server_registry.py +89 -0
- fast_agent/py.typed +0 -0
- fast_agent/resources/examples/data-analysis/analysis-campaign.py +189 -0
- fast_agent/resources/examples/data-analysis/analysis.py +68 -0
- fast_agent/resources/examples/data-analysis/fastagent.config.yaml +41 -0
- fast_agent/resources/examples/data-analysis/mount-point/WA_Fn-UseC_-HR-Employee-Attrition.csv +1471 -0
- fast_agent/resources/examples/mcp/elicitations/elicitation_account_server.py +88 -0
- fast_agent/resources/examples/mcp/elicitations/elicitation_forms_server.py +297 -0
- fast_agent/resources/examples/mcp/elicitations/elicitation_game_server.py +164 -0
- fast_agent/resources/examples/mcp/elicitations/fastagent.config.yaml +35 -0
- fast_agent/resources/examples/mcp/elicitations/fastagent.secrets.yaml.example +17 -0
- fast_agent/resources/examples/mcp/elicitations/forms_demo.py +107 -0
- fast_agent/resources/examples/mcp/elicitations/game_character.py +65 -0
- fast_agent/resources/examples/mcp/elicitations/game_character_handler.py +256 -0
- fast_agent/resources/examples/mcp/elicitations/tool_call.py +21 -0
- fast_agent/resources/examples/mcp/state-transfer/agent_one.py +18 -0
- fast_agent/resources/examples/mcp/state-transfer/agent_two.py +18 -0
- fast_agent/resources/examples/mcp/state-transfer/fastagent.config.yaml +27 -0
- fast_agent/resources/examples/mcp/state-transfer/fastagent.secrets.yaml.example +15 -0
- fast_agent/resources/examples/researcher/fastagent.config.yaml +61 -0
- fast_agent/resources/examples/researcher/researcher-eval.py +53 -0
- fast_agent/resources/examples/researcher/researcher-imp.py +189 -0
- fast_agent/resources/examples/researcher/researcher.py +36 -0
- fast_agent/resources/examples/tensorzero/.env.sample +2 -0
- fast_agent/resources/examples/tensorzero/Makefile +31 -0
- fast_agent/resources/examples/tensorzero/README.md +56 -0
- fast_agent/resources/examples/tensorzero/agent.py +35 -0
- fast_agent/resources/examples/tensorzero/demo_images/clam.jpg +0 -0
- fast_agent/resources/examples/tensorzero/demo_images/crab.png +0 -0
- fast_agent/resources/examples/tensorzero/demo_images/shrimp.png +0 -0
- fast_agent/resources/examples/tensorzero/docker-compose.yml +105 -0
- fast_agent/resources/examples/tensorzero/fastagent.config.yaml +19 -0
- fast_agent/resources/examples/tensorzero/image_demo.py +67 -0
- fast_agent/resources/examples/tensorzero/mcp_server/Dockerfile +25 -0
- fast_agent/resources/examples/tensorzero/mcp_server/entrypoint.sh +35 -0
- fast_agent/resources/examples/tensorzero/mcp_server/mcp_server.py +31 -0
- fast_agent/resources/examples/tensorzero/mcp_server/pyproject.toml +11 -0
- fast_agent/resources/examples/tensorzero/simple_agent.py +25 -0
- fast_agent/resources/examples/tensorzero/tensorzero_config/system_schema.json +29 -0
- fast_agent/resources/examples/tensorzero/tensorzero_config/system_template.minijinja +11 -0
- fast_agent/resources/examples/tensorzero/tensorzero_config/tensorzero.toml +35 -0
- fast_agent/resources/examples/workflows/agents_as_tools_extended.py +73 -0
- fast_agent/resources/examples/workflows/agents_as_tools_simple.py +50 -0
- fast_agent/resources/examples/workflows/chaining.py +37 -0
- fast_agent/resources/examples/workflows/evaluator.py +77 -0
- fast_agent/resources/examples/workflows/fastagent.config.yaml +26 -0
- fast_agent/resources/examples/workflows/graded_report.md +89 -0
- fast_agent/resources/examples/workflows/human_input.py +28 -0
- fast_agent/resources/examples/workflows/maker.py +156 -0
- fast_agent/resources/examples/workflows/orchestrator.py +70 -0
- fast_agent/resources/examples/workflows/parallel.py +56 -0
- fast_agent/resources/examples/workflows/router.py +69 -0
- fast_agent/resources/examples/workflows/short_story.md +13 -0
- fast_agent/resources/examples/workflows/short_story.txt +19 -0
- fast_agent/resources/setup/.gitignore +30 -0
- fast_agent/resources/setup/agent.py +28 -0
- fast_agent/resources/setup/fastagent.config.yaml +65 -0
- fast_agent/resources/setup/fastagent.secrets.yaml.example +38 -0
- fast_agent/resources/setup/pyproject.toml.tmpl +23 -0
- fast_agent/skills/__init__.py +9 -0
- fast_agent/skills/registry.py +235 -0
- fast_agent/tools/elicitation.py +369 -0
- fast_agent/tools/shell_runtime.py +402 -0
- fast_agent/types/__init__.py +59 -0
- fast_agent/types/conversation_summary.py +294 -0
- fast_agent/types/llm_stop_reason.py +78 -0
- fast_agent/types/message_search.py +249 -0
- fast_agent/ui/__init__.py +38 -0
- fast_agent/ui/console.py +59 -0
- fast_agent/ui/console_display.py +1080 -0
- fast_agent/ui/elicitation_form.py +946 -0
- fast_agent/ui/elicitation_style.py +59 -0
- fast_agent/ui/enhanced_prompt.py +1400 -0
- fast_agent/ui/history_display.py +734 -0
- fast_agent/ui/interactive_prompt.py +1199 -0
- fast_agent/ui/markdown_helpers.py +104 -0
- fast_agent/ui/markdown_truncator.py +1004 -0
- fast_agent/ui/mcp_display.py +857 -0
- fast_agent/ui/mcp_ui_utils.py +235 -0
- fast_agent/ui/mermaid_utils.py +169 -0
- fast_agent/ui/message_primitives.py +50 -0
- fast_agent/ui/notification_tracker.py +205 -0
- fast_agent/ui/plain_text_truncator.py +68 -0
- fast_agent/ui/progress_display.py +10 -0
- fast_agent/ui/rich_progress.py +195 -0
- fast_agent/ui/streaming.py +774 -0
- fast_agent/ui/streaming_buffer.py +449 -0
- fast_agent/ui/tool_display.py +422 -0
- fast_agent/ui/usage_display.py +204 -0
- fast_agent/utils/__init__.py +5 -0
- fast_agent/utils/reasoning_stream_parser.py +77 -0
- fast_agent/utils/time.py +22 -0
- fast_agent/workflow_telemetry.py +261 -0
- fast_agent_mcp-0.4.7.dist-info/METADATA +788 -0
- fast_agent_mcp-0.4.7.dist-info/RECORD +261 -0
- fast_agent_mcp-0.4.7.dist-info/WHEEL +4 -0
- fast_agent_mcp-0.4.7.dist-info/entry_points.txt +7 -0
- fast_agent_mcp-0.4.7.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
|
|
3
|
+
from fast_agent import FastAgent
|
|
4
|
+
|
|
5
|
+
CONFIG_FILE = "fastagent.config.yaml"
|
|
6
|
+
fast = FastAgent("fast-agent example", config_path=CONFIG_FILE, ignore_unknown_args=True)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@fast.agent(
|
|
10
|
+
name="default",
|
|
11
|
+
instruction="""
|
|
12
|
+
You are an agent dedicated to helping developers understand the relationship between TensoZero and fast-agent. If the user makes a request
|
|
13
|
+
that requires you to invoke the test tools, please do so. When you use the tool, describe your rationale for doing so.
|
|
14
|
+
""",
|
|
15
|
+
servers=["tester"],
|
|
16
|
+
)
|
|
17
|
+
async def main():
|
|
18
|
+
async with fast.run() as agent_app:
|
|
19
|
+
agent_name = "default"
|
|
20
|
+
print("\nStarting interactive session with template_vars set via decorator...")
|
|
21
|
+
await agent_app.interactive(agent=agent_name)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
if __name__ == "__main__":
|
|
25
|
+
asyncio.run(main()) # type: ignore
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"required": [
|
|
5
|
+
"TEST_VARIABLE_1",
|
|
6
|
+
"TEST_VARIABLE_2",
|
|
7
|
+
"TEST_VARIABLE_3",
|
|
8
|
+
"TEST_VARIABLE_4"
|
|
9
|
+
],
|
|
10
|
+
"properties": {
|
|
11
|
+
"TEST_VARIABLE_1": {
|
|
12
|
+
"type": "string",
|
|
13
|
+
"description": "Test variable 1"
|
|
14
|
+
},
|
|
15
|
+
"TEST_VARIABLE_2": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"description": "Test variable 2"
|
|
18
|
+
},
|
|
19
|
+
"TEST_VARIABLE_3": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"description": "Test variable 3"
|
|
22
|
+
},
|
|
23
|
+
"TEST_VARIABLE_4": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"description": "Test variable 4"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"additionalProperties": false
|
|
29
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Your purpose is to demo the integration between tensorzero, an open source project dedicated to improving LLM inference calls, and fast-agent, a framework for MCP-compatible agentic modelling. When interacting with developers, strive to be as helpful to possible, specifically as relates to technical questions about tensorzero, fast-agent, or MCPs.
|
|
2
|
+
|
|
3
|
+
If you are ever asked to recite a poem, recite this one:
|
|
4
|
+
|
|
5
|
+
{{ TEST_VARIABLE_1 }}
|
|
6
|
+
|
|
7
|
+
{{ TEST_VARIABLE_2 }}
|
|
8
|
+
|
|
9
|
+
{{ TEST_VARIABLE_3 }}
|
|
10
|
+
|
|
11
|
+
{{ TEST_VARIABLE_4 }}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[functions.test_chat]
|
|
2
|
+
type = "chat"
|
|
3
|
+
system_schema = "./system_schema.json"
|
|
4
|
+
|
|
5
|
+
[functions.test_chat.variants.gpt_4o_mini]
|
|
6
|
+
type = "chat_completion"
|
|
7
|
+
model = "openai::gpt-4o-mini"
|
|
8
|
+
weight = 0.5
|
|
9
|
+
system_template = "./system_template.minijinja"
|
|
10
|
+
|
|
11
|
+
[functions.test_chat.variants.claude_3_5_haiku]
|
|
12
|
+
type = "chat_completion"
|
|
13
|
+
model = "anthropic::claude-3-5-haiku-20241022"
|
|
14
|
+
weight = 0.5
|
|
15
|
+
system_template = "./system_template.minijinja"
|
|
16
|
+
|
|
17
|
+
[functions.simple_chat]
|
|
18
|
+
type = "chat"
|
|
19
|
+
|
|
20
|
+
[functions.simple_chat.variants.gpt_4o_mini]
|
|
21
|
+
type = "chat_completion"
|
|
22
|
+
model = "openai::gpt-4o-mini"
|
|
23
|
+
weight = 0.5
|
|
24
|
+
|
|
25
|
+
[functions.simple_chat.variants.claude_3_5_haiku]
|
|
26
|
+
type = "chat_completion"
|
|
27
|
+
model = "anthropic::claude-3-5-haiku-20241022"
|
|
28
|
+
weight = 0.5
|
|
29
|
+
|
|
30
|
+
# Object Storage Configuration for MinIO, simulating AWS S3 bucket
|
|
31
|
+
[object_storage]
|
|
32
|
+
type = "s3_compatible"
|
|
33
|
+
endpoint = "http://minio:9000"
|
|
34
|
+
bucket_name = "tensorzero"
|
|
35
|
+
allow_http = true
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Agents-as-Tools example: project managers for NY and London.
|
|
2
|
+
|
|
3
|
+
Parent agent ("PMO-orchestrator") calls two child agents
|
|
4
|
+
("NY-Project-Manager" and "London-Project-Manager") as tools. Each child uses
|
|
5
|
+
the ``time`` MCP server for local time and the ``fetch`` MCP server for a short
|
|
6
|
+
news-based update on the given topics.
|
|
7
|
+
|
|
8
|
+
Defaults: clones fork parent history (no merge-back), no timeout, no parallel cap,
|
|
9
|
+
and collapses progress display after the first 20 instances.
|
|
10
|
+
To change behavior, pass decorator args such as
|
|
11
|
+
`history_mode=HistoryMode.FORK_AND_MERGE`, `child_timeout_sec=600`,
|
|
12
|
+
`max_parallel=8`, `max_display_instances=10`
|
|
13
|
+
(HistoryMode import: fast_agent.agents.workflow.agents_as_tools_agent).
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import asyncio
|
|
17
|
+
|
|
18
|
+
from fast_agent import FastAgent
|
|
19
|
+
|
|
20
|
+
# Create the application
|
|
21
|
+
fast = FastAgent("Agents-as-Tools demo")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@fast.agent(
|
|
25
|
+
name="NY-Project-Manager",
|
|
26
|
+
instruction=(
|
|
27
|
+
"You are a New York project manager. For each given topic, get the "
|
|
28
|
+
"current local time in New York and a brief, project-relevant news "
|
|
29
|
+
"summary using the 'time' and 'fetch' MCP servers. If a source returns "
|
|
30
|
+
"HTTP 403 or is blocked by robots.txt, try up to five alternative "
|
|
31
|
+
"public sources before giving up and clearly state any remaining "
|
|
32
|
+
"access limits. Hint: Fast-Agent site: https://fast-agent.ai"
|
|
33
|
+
),
|
|
34
|
+
servers=[
|
|
35
|
+
"time",
|
|
36
|
+
"fetch",
|
|
37
|
+
], # MCP servers 'time' and 'fetch' configured in fastagent.config.yaml
|
|
38
|
+
)
|
|
39
|
+
@fast.agent(
|
|
40
|
+
name="London-Project-Manager",
|
|
41
|
+
instruction=(
|
|
42
|
+
"You are a London project manager. For each given topic, get the "
|
|
43
|
+
"current local time in London and a brief, project-relevant news "
|
|
44
|
+
"summary using the 'time' and 'fetch' MCP servers. If a source returns "
|
|
45
|
+
"HTTP 403 or is blocked by robots.txt, try up to five alternative "
|
|
46
|
+
"public sources before giving up and clearly state any remaining "
|
|
47
|
+
"access limits. Hint: BBC: https://www.bbc.com/ and FT: https://www.ft.com/"
|
|
48
|
+
),
|
|
49
|
+
servers=["time", "fetch"],
|
|
50
|
+
)
|
|
51
|
+
@fast.agent(
|
|
52
|
+
name="PMO-orchestrator",
|
|
53
|
+
instruction=(
|
|
54
|
+
"Get project updates from the New York and London project managers. "
|
|
55
|
+
"Ask NY-Project-Manager three times about different projects: Anthropic, "
|
|
56
|
+
"evalstate/fast-agent, and OpenAI, and London-Project-Manager for economics review. "
|
|
57
|
+
"Return a brief, concise combined summary with clear city/time/topic labels."
|
|
58
|
+
),
|
|
59
|
+
default=True,
|
|
60
|
+
agents=[
|
|
61
|
+
"NY-Project-Manager",
|
|
62
|
+
"London-Project-Manager",
|
|
63
|
+
], # children are exposed as tools: agent__NY-Project-Manager, agent__London-Project-Manager
|
|
64
|
+
# optional: history_mode="fork_and_merge", child_timeout_sec=600, max_parallel=8, max_display_instances=10
|
|
65
|
+
)
|
|
66
|
+
async def main() -> None:
|
|
67
|
+
async with fast.run() as agent:
|
|
68
|
+
result = await agent("pls send me daily review.")
|
|
69
|
+
print(result)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
if __name__ == "__main__":
|
|
73
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Simple Agents-as-Tools PMO example.
|
|
2
|
+
|
|
3
|
+
Parent agent ("PMO-orchestrator") calls two child agents ("NY-Project-Manager"
|
|
4
|
+
and "London-Project-Manager") as tools. Each child uses the ``time`` MCP
|
|
5
|
+
server to include local time in a brief report.
|
|
6
|
+
|
|
7
|
+
Defaults: clones fork parent history (no merge-back), no timeout, no parallel cap,
|
|
8
|
+
and collapses progress display after the first 20 instances.
|
|
9
|
+
If you want merge-back or other limits, pass decorator args:
|
|
10
|
+
`history_mode=HistoryMode.FORK_AND_MERGE`, `child_timeout_sec=600`,
|
|
11
|
+
`max_parallel=8`, `max_display_instances=10`
|
|
12
|
+
(HistoryMode import: fast_agent.agents.workflow.agents_as_tools_agent).
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import asyncio
|
|
16
|
+
|
|
17
|
+
from fast_agent import FastAgent
|
|
18
|
+
|
|
19
|
+
fast = FastAgent("Agents-as-Tools simple demo")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@fast.agent(
|
|
23
|
+
name="NY-Project-Manager",
|
|
24
|
+
instruction="Return current time and project status.",
|
|
25
|
+
servers=["time"], # MCP server 'time' configured in fastagent.config.yaml
|
|
26
|
+
)
|
|
27
|
+
@fast.agent(
|
|
28
|
+
name="London-Project-Manager",
|
|
29
|
+
instruction="Return current time and news.",
|
|
30
|
+
servers=["time"],
|
|
31
|
+
)
|
|
32
|
+
@fast.agent(
|
|
33
|
+
name="PMO-orchestrator",
|
|
34
|
+
instruction="Get reports. Separate call per topic. NY: {OpenAI, Fast-Agent, Anthropic}, London: Economics",
|
|
35
|
+
default=True,
|
|
36
|
+
agents=[
|
|
37
|
+
"NY-Project-Manager",
|
|
38
|
+
"London-Project-Manager",
|
|
39
|
+
], # children are exposed as tools: agent__NY-Project-Manager, agent__London-Project-Manager
|
|
40
|
+
# optional: history_mode="fork_and_merge", child_timeout_sec=600, max_parallel=8, max_display_instances=10
|
|
41
|
+
)
|
|
42
|
+
async def main() -> None:
|
|
43
|
+
async with fast.run() as agent:
|
|
44
|
+
result = await agent("Get PMO report")
|
|
45
|
+
await agent.interactive()
|
|
46
|
+
print(result)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
if __name__ == "__main__":
|
|
50
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
|
|
3
|
+
from fast_agent import FastAgent
|
|
4
|
+
|
|
5
|
+
# Create the application
|
|
6
|
+
fast = FastAgent("Agent Chaining")
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@fast.agent(
|
|
10
|
+
"url_fetcher",
|
|
11
|
+
instruction="Given a URL, provide a complete and comprehensive summary",
|
|
12
|
+
servers=["fetch"],
|
|
13
|
+
)
|
|
14
|
+
@fast.agent(
|
|
15
|
+
"social_media",
|
|
16
|
+
instruction="""
|
|
17
|
+
Write a 280 character social media post for any given text.
|
|
18
|
+
Respond only with the post, never use hashtags.
|
|
19
|
+
""",
|
|
20
|
+
)
|
|
21
|
+
@fast.chain(
|
|
22
|
+
name="post_writer",
|
|
23
|
+
sequence=["url_fetcher", "social_media"],
|
|
24
|
+
default=True,
|
|
25
|
+
)
|
|
26
|
+
async def main() -> None:
|
|
27
|
+
async with fast.run() as agent:
|
|
28
|
+
# using chain workflow
|
|
29
|
+
await agent.post_writer.send("https://llmindset.co.uk")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# alternative syntax for above is result = agent["post_writer"].send(message)
|
|
33
|
+
# alternative syntax for above is result = agent["post_writer"].prompt()
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if __name__ == "__main__":
|
|
37
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This demonstrates creating an optimizer and evaluator to iteratively improve content.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
|
|
7
|
+
from fast_agent import FastAgent
|
|
8
|
+
|
|
9
|
+
# Create the application
|
|
10
|
+
fast = FastAgent("Evaluator-Optimizer")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# Define generator agent
|
|
14
|
+
@fast.agent(
|
|
15
|
+
name="generator",
|
|
16
|
+
instruction="""You are a career coach specializing in cover letter writing.
|
|
17
|
+
You are tasked with generating a compelling cover letter given the job posting,
|
|
18
|
+
candidate details, and company information. Tailor the response to the company and job requirements.
|
|
19
|
+
""",
|
|
20
|
+
servers=["fetch"],
|
|
21
|
+
model="gpt-5-nano.low",
|
|
22
|
+
use_history=True,
|
|
23
|
+
)
|
|
24
|
+
# Define evaluator agent
|
|
25
|
+
@fast.agent(
|
|
26
|
+
name="evaluator",
|
|
27
|
+
instruction="""Evaluate the following response based on the criteria below:
|
|
28
|
+
1. Clarity: Is the language clear, concise, and grammatically correct?
|
|
29
|
+
2. Specificity: Does the response include relevant and concrete details tailored to the job description?
|
|
30
|
+
3. Relevance: Does the response align with the prompt and avoid unnecessary information?
|
|
31
|
+
4. Tone and Style: Is the tone professional and appropriate for the context?
|
|
32
|
+
5. Persuasiveness: Does the response effectively highlight the candidate's value?
|
|
33
|
+
6. Grammar and Mechanics: Are there any spelling or grammatical issues?
|
|
34
|
+
7. Feedback Alignment: Has the response addressed feedback from previous iterations?
|
|
35
|
+
|
|
36
|
+
For each criterion:
|
|
37
|
+
- Provide a rating (EXCELLENT, GOOD, FAIR, or POOR).
|
|
38
|
+
- Offer specific feedback or suggestions for improvement.
|
|
39
|
+
|
|
40
|
+
Summarize your evaluation as a structured response with:
|
|
41
|
+
- Overall quality rating.
|
|
42
|
+
- Specific feedback and areas for improvement.""",
|
|
43
|
+
model="o3-mini.medium",
|
|
44
|
+
)
|
|
45
|
+
# Define the evaluator-optimizer workflow
|
|
46
|
+
@fast.evaluator_optimizer(
|
|
47
|
+
name="cover_letter_writer",
|
|
48
|
+
generator="generator", # Reference to generator agent
|
|
49
|
+
evaluator="evaluator", # Reference to evaluator agent
|
|
50
|
+
min_rating="EXCELLENT", # Strive for excellence
|
|
51
|
+
max_refinements=3, # Maximum iterations
|
|
52
|
+
)
|
|
53
|
+
async def main() -> None:
|
|
54
|
+
async with fast.run() as agent:
|
|
55
|
+
job_posting = (
|
|
56
|
+
"Software Engineer at LastMile AI. Responsibilities include developing AI systems, "
|
|
57
|
+
"collaborating with cross-functional teams, and enhancing scalability. Skills required: "
|
|
58
|
+
"Python, distributed systems, and machine learning."
|
|
59
|
+
)
|
|
60
|
+
candidate_details = (
|
|
61
|
+
"Alex Johnson, 3 years in machine learning, contributor to open-source AI projects, "
|
|
62
|
+
"proficient in Python and TensorFlow. Motivated by building scalable AI systems to solve real-world problems."
|
|
63
|
+
)
|
|
64
|
+
company_information = (
|
|
65
|
+
"Look up from the LastMile AI About page: https://lastmileai.dev/about"
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
# Send the task
|
|
69
|
+
await agent.cover_letter_writer.send(
|
|
70
|
+
f"Write a cover letter for the following job posting: {job_posting}\n\n"
|
|
71
|
+
f"Candidate Details: {candidate_details}\n\n"
|
|
72
|
+
f"Company information: {company_information}",
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
if __name__ == "__main__":
|
|
77
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Please edit this configuration file to match your environment (on Windows).
|
|
2
|
+
# Examples in comments below - check/change the paths.
|
|
3
|
+
#
|
|
4
|
+
#
|
|
5
|
+
|
|
6
|
+
logger:
|
|
7
|
+
type: file
|
|
8
|
+
level: error
|
|
9
|
+
truncate_tools: true
|
|
10
|
+
|
|
11
|
+
mcp:
|
|
12
|
+
servers:
|
|
13
|
+
filesystem:
|
|
14
|
+
# On windows update the command and arguments to use `node` and the absolute path to the server.
|
|
15
|
+
# Use `npm i -g @modelcontextprotocol/server-filesystem` to install the server globally.
|
|
16
|
+
# Use `npm -g root` to find the global node_modules path.`
|
|
17
|
+
# command: "node"
|
|
18
|
+
# args: ["c:/Program Files/nodejs/node_modules/@modelcontextprotocol/server-filesystem/dist/index.js","."]
|
|
19
|
+
command: "npx"
|
|
20
|
+
args: ["-y", "@modelcontextprotocol/server-filesystem", "."]
|
|
21
|
+
fetch:
|
|
22
|
+
command: "uvx"
|
|
23
|
+
args: ["mcp-server-fetch"]
|
|
24
|
+
time:
|
|
25
|
+
command: "uvx"
|
|
26
|
+
args: ["mcp-server-time"]
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Graded Report: "The Kittens Castle Adventure"
|
|
2
|
+
|
|
3
|
+
## Proofreading Feedback
|
|
4
|
+
|
|
5
|
+
### Spelling Errors
|
|
6
|
+
1. "Adventuer" → "Adventure"
|
|
7
|
+
2. "lil" → "little"
|
|
8
|
+
3. "name" → "named"
|
|
9
|
+
4. "threw" → "through"
|
|
10
|
+
5. "mystirus" → "mysterious"
|
|
11
|
+
6. "forrest" → "forest"
|
|
12
|
+
7. "was" → "were"
|
|
13
|
+
8. "an" → "and"
|
|
14
|
+
9. "Suddenlee" → "Suddenly"
|
|
15
|
+
10. "sawd" → "saw"
|
|
16
|
+
11. "somthing" → "something"
|
|
17
|
+
12. "chese" → "cheese"
|
|
18
|
+
13. "windos" → "windows"
|
|
19
|
+
14. "turrits" → "turrets"
|
|
20
|
+
15. "tuch" → "touch"
|
|
21
|
+
16. "clowds" → "clouds"
|
|
22
|
+
17. "doars" → "doors"
|
|
23
|
+
18. "enuff" → "enough"
|
|
24
|
+
19. "elefant" → "elephant"
|
|
25
|
+
20. "sed" → "said"
|
|
26
|
+
21. "tale" → "tail"
|
|
27
|
+
22. "poofy" → "puffy"
|
|
28
|
+
23. "fowned" → "found"
|
|
29
|
+
24. "meowed" → added missing period
|
|
30
|
+
25. "smallist" → "smallest"
|
|
31
|
+
26. "rond" → "round"
|
|
32
|
+
27. "climed" → "climbed"
|
|
33
|
+
28. "slip-slidin" → "slip-sliding"
|
|
34
|
+
29. "smoth" → "smooth"
|
|
35
|
+
30. "surfase" → "surface"
|
|
36
|
+
31. "ful" → "full"
|
|
37
|
+
32. "dangling" → added missing period
|
|
38
|
+
33. "JINGEL" → "jingle"
|
|
39
|
+
34. "paradyse" → "paradise"
|
|
40
|
+
35. "figur" → "figure"
|
|
41
|
+
36. "gaurd" → "guard"
|
|
42
|
+
37. "sumthing" → "something"
|
|
43
|
+
38. "mor" → "more"
|
|
44
|
+
39. "hudeld" → "huddled"
|
|
45
|
+
40. "togethar" → "together"
|
|
46
|
+
41. "there" → "their"
|
|
47
|
+
42. "happan" → "happen"
|
|
48
|
+
43. "amazeing" → "amazing"
|
|
49
|
+
|
|
50
|
+
### Grammar and Syntax Errors
|
|
51
|
+
1. Inconsistent verb tenses throughout the story
|
|
52
|
+
2. Improper use of articles (a/an)
|
|
53
|
+
3. Missing punctuation
|
|
54
|
+
4. Lack of subject-verb agreement
|
|
55
|
+
5. Incorrect capitalization
|
|
56
|
+
|
|
57
|
+
### Style and Formatting Recommendations
|
|
58
|
+
1. Use standard capitalization for proper nouns
|
|
59
|
+
2. Maintain consistent verb tense (past tense recommended)
|
|
60
|
+
3. Use proper punctuation
|
|
61
|
+
4. Avoid excessive use of exclamation points
|
|
62
|
+
5. Use standard spelling for all words
|
|
63
|
+
|
|
64
|
+
## Factuality and Logical Consistency
|
|
65
|
+
- The story is a fictional narrative about three kittens, so traditional factual constraints do not strictly apply
|
|
66
|
+
- The narrative maintains internal logical consistency
|
|
67
|
+
- The cliffhanger ending leaves room for imagination
|
|
68
|
+
|
|
69
|
+
## Style Adherence
|
|
70
|
+
### APA Formatting Guidelines
|
|
71
|
+
- Title should be centered and in title case
|
|
72
|
+
- Use 12-point Times New Roman font (not applicable in markdown)
|
|
73
|
+
- Double-spacing recommended (not applicable in markdown)
|
|
74
|
+
- 1-inch margins (not applicable in markdown)
|
|
75
|
+
|
|
76
|
+
### Recommendations for Improvement
|
|
77
|
+
1. Proofread and correct all spelling errors
|
|
78
|
+
2. Maintain consistent grammar and syntax
|
|
79
|
+
3. Use standard English spelling
|
|
80
|
+
4. Add more descriptive language
|
|
81
|
+
5. Develop a more structured narrative arc
|
|
82
|
+
|
|
83
|
+
## Overall Assessment
|
|
84
|
+
**Writing Quality**: Needs Significant Improvement
|
|
85
|
+
**Creativity**: Excellent
|
|
86
|
+
**Potential**: High
|
|
87
|
+
|
|
88
|
+
### Suggested Revision
|
|
89
|
+
Revise the text to correct spelling, grammar, and syntax while preserving the original creative narrative and imaginative elements.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Agent which demonstrates Human Input tool
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
|
|
7
|
+
from fast_agent import FastAgent
|
|
8
|
+
|
|
9
|
+
# Create the application
|
|
10
|
+
fast = FastAgent("Human Input")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# Define the agent
|
|
14
|
+
@fast.agent(
|
|
15
|
+
instruction="An AI agent that assists with basic tasks. Request Human Input when needed - for example"
|
|
16
|
+
"if being asked to predict a number sequence or pretending to take pizza orders.",
|
|
17
|
+
human_input=True,
|
|
18
|
+
)
|
|
19
|
+
async def main() -> None:
|
|
20
|
+
async with fast.run() as agent:
|
|
21
|
+
# this usually causes the LLM to request the Human Input Tool
|
|
22
|
+
await agent("print the next number in the sequence")
|
|
23
|
+
await agent("pretend to be a pizza restaurant and take the users order")
|
|
24
|
+
await agent.interactive(default_prompt="STOP")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
if __name__ == "__main__":
|
|
28
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"""
|
|
2
|
+
MAKER: Massively decomposed Agentic processes with K-voting Error Reduction.
|
|
3
|
+
|
|
4
|
+
This example demonstrates the MAKER workflow pattern for achieving high
|
|
5
|
+
reliability through statistical consensus voting.
|
|
6
|
+
|
|
7
|
+
Based on the paper:
|
|
8
|
+
"Solving a Million-Step LLM Task with Zero Errors"
|
|
9
|
+
Meyerson et al., 2024
|
|
10
|
+
https://arxiv.org/abs/2511.09030
|
|
11
|
+
|
|
12
|
+
Key Concepts:
|
|
13
|
+
-------------
|
|
14
|
+
1. **First-to-ahead-by-k Voting**: Multiple samples are drawn from a worker
|
|
15
|
+
agent. The first response to achieve a k-vote margin over all alternatives
|
|
16
|
+
wins. This provides provable error bounds.
|
|
17
|
+
|
|
18
|
+
2. **Red-Flagging**: Responses that show signs of confusion (too long,
|
|
19
|
+
malformed) are discarded before voting, improving effective success rate.
|
|
20
|
+
|
|
21
|
+
3. **Cost-Effective Reliability**: By trading compute (multiple samples) for
|
|
22
|
+
accuracy (statistical consensus), cheap models can achieve high reliability.
|
|
23
|
+
|
|
24
|
+
When to Use MAKER:
|
|
25
|
+
------------------
|
|
26
|
+
MAKER is designed for **long chains of simple steps** where errors compound:
|
|
27
|
+
|
|
28
|
+
Good use cases:
|
|
29
|
+
- **ETL pipelines**: 1000s of row transformations - one bad parse = corrupted data
|
|
30
|
+
- **Code migration**: 1000s of file changes - one syntax error = build fails
|
|
31
|
+
- **Document processing**: 1000s of pages - one missed field = compliance failure
|
|
32
|
+
- **Data validation**: Millions of records - one wrong validation = bad data in prod
|
|
33
|
+
- **Automated testing**: 1000s of assertions - one false positive = wasted debugging
|
|
34
|
+
- **Cost optimization**: Cheap model + voting can replace expensive model
|
|
35
|
+
|
|
36
|
+
When NOT to use MAKER:
|
|
37
|
+
- Single classifications (just use a good model - 95% accuracy is fine)
|
|
38
|
+
- Creative/open-ended tasks (no "correct" answer to vote on)
|
|
39
|
+
- Complex reasoning (need smarter model, not more samples)
|
|
40
|
+
- Tasks where occasional errors are acceptable
|
|
41
|
+
|
|
42
|
+
The Math:
|
|
43
|
+
---------
|
|
44
|
+
- 95% per-step accuracy over 100 steps = 0.6% overall success (0.95^100)
|
|
45
|
+
- 99.9% per-step accuracy (with MAKER) over 100 steps = 90% overall success
|
|
46
|
+
- For million-step tasks, even 99% per-step fails; MAKER enables 99.99%+
|
|
47
|
+
|
|
48
|
+
Demo Use Case:
|
|
49
|
+
--------------
|
|
50
|
+
This example shows customer message intent classification. While modern LLMs
|
|
51
|
+
are quite consistent on this task (you'll see 3:0 votes), the mechanism
|
|
52
|
+
demonstrates how voting works. In production with harder tasks or longer
|
|
53
|
+
chains, MAKER's value becomes critical.
|
|
54
|
+
|
|
55
|
+
Usage:
|
|
56
|
+
------
|
|
57
|
+
uv run examples/workflows/maker.py
|
|
58
|
+
|
|
59
|
+
Try modifying k (voting margin) and observe how it affects reliability vs cost.
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
import asyncio
|
|
63
|
+
|
|
64
|
+
from fast_agent import FastAgent
|
|
65
|
+
|
|
66
|
+
fast = FastAgent("MAKER Example")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# Define a classifier using a cheap model (Haiku) - may give inconsistent results
|
|
70
|
+
# on ambiguous messages, which is why we wrap it with MAKER for reliability
|
|
71
|
+
@fast.agent(
|
|
72
|
+
name="classifier",
|
|
73
|
+
model="claude-3-haiku-20240307",
|
|
74
|
+
instruction="""You are a customer support intent classifier.
|
|
75
|
+
Classify the customer message into exactly one of: COMPLAINT, QUESTION, REQUEST, FEEDBACK.
|
|
76
|
+
Respond with ONLY the single word classification, nothing else.
|
|
77
|
+
|
|
78
|
+
Examples:
|
|
79
|
+
- "This product is broken!" → COMPLAINT
|
|
80
|
+
- "How do I reset my password?" → QUESTION
|
|
81
|
+
- "Please cancel my subscription" → REQUEST
|
|
82
|
+
- "Just wanted to say I love the new feature" → FEEDBACK""",
|
|
83
|
+
)
|
|
84
|
+
# Wrap with MAKER for reliable, consistent classification
|
|
85
|
+
@fast.maker(
|
|
86
|
+
name="reliable_classifier",
|
|
87
|
+
worker="classifier",
|
|
88
|
+
k=3, # Require 3-vote margin for consensus
|
|
89
|
+
max_samples=10, # Max attempts before falling back to plurality
|
|
90
|
+
match_strategy="normalized", # Ignore case/whitespace differences
|
|
91
|
+
red_flag_max_length=20, # Discard verbose responses (should be one word)
|
|
92
|
+
)
|
|
93
|
+
async def main():
|
|
94
|
+
"""Demonstrate MAKER voting for reliable intent classification."""
|
|
95
|
+
async with fast.run() as agent:
|
|
96
|
+
print("=" * 70)
|
|
97
|
+
print("MAKER: Massively decomposed Agentic processes")
|
|
98
|
+
print(" with K-voting Error Reduction")
|
|
99
|
+
print("=" * 70)
|
|
100
|
+
print()
|
|
101
|
+
print("This example classifies customer messages where intent is ambiguous.")
|
|
102
|
+
print("MAKER voting ensures consistent routing even for edge cases.")
|
|
103
|
+
print()
|
|
104
|
+
|
|
105
|
+
# Ambiguous customer messages where intent is unclear
|
|
106
|
+
test_cases = [
|
|
107
|
+
"I've been waiting for 3 days now.", # Complaint? Status question?
|
|
108
|
+
"Can someone explain how this works?", # Question? Request for help?
|
|
109
|
+
"This isn't what I expected.", # Complaint? Feedback?
|
|
110
|
+
"I'd like to speak to a manager.", # Complaint? Request?
|
|
111
|
+
"Why does this keep happening?", # Complaint? Question?
|
|
112
|
+
"Just wanted to let you know about this.", # Feedback? Complaint?
|
|
113
|
+
"Is there any way to get a refund?", # Question? Request?
|
|
114
|
+
"The new update changed everything.", # Complaint? Feedback?
|
|
115
|
+
]
|
|
116
|
+
|
|
117
|
+
# Collect all results first
|
|
118
|
+
results = []
|
|
119
|
+
for text in test_cases:
|
|
120
|
+
result = await agent.reliable_classifier.send(text)
|
|
121
|
+
stats = agent.reliable_classifier.last_result
|
|
122
|
+
results.append((text, result, stats))
|
|
123
|
+
|
|
124
|
+
# Display all results together
|
|
125
|
+
print("-" * 70)
|
|
126
|
+
print(f"{'Text':<50} {'Result':<10} {'Samples':<8} {'Votes'}")
|
|
127
|
+
print("-" * 70)
|
|
128
|
+
|
|
129
|
+
for text, result, stats in results:
|
|
130
|
+
votes_str = ""
|
|
131
|
+
samples = ""
|
|
132
|
+
if stats:
|
|
133
|
+
votes_str = ", ".join(f"{k}:{v}" for k, v in stats.votes.items())
|
|
134
|
+
samples = str(stats.total_samples)
|
|
135
|
+
|
|
136
|
+
print(f"{text:<50} {result:<10} {samples:<8} {votes_str}")
|
|
137
|
+
|
|
138
|
+
print("-" * 70)
|
|
139
|
+
print()
|
|
140
|
+
print("Notice how MAKER provides consistent routing decisions even for")
|
|
141
|
+
print("ambiguous messages by voting across multiple samples.")
|
|
142
|
+
print()
|
|
143
|
+
|
|
144
|
+
# Summary statistics
|
|
145
|
+
total_samples = sum(r[2].total_samples for r in results if r[2])
|
|
146
|
+
all_converged = all(r[2].converged for r in results if r[2])
|
|
147
|
+
print("Summary:")
|
|
148
|
+
print(f" - Total API calls: {total_samples}")
|
|
149
|
+
print(f" - All converged: {all_converged}")
|
|
150
|
+
print(f" - Texts classified: {len(results)}")
|
|
151
|
+
print()
|
|
152
|
+
print("=" * 70)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
if __name__ == "__main__":
|
|
156
|
+
asyncio.run(main())
|