fast-agent-mcp 0.2.58__py3-none-any.whl → 0.3.1__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.
Potentially problematic release.
This version of fast-agent-mcp might be problematic. Click here for more details.
- fast_agent/__init__.py +127 -0
- fast_agent/agents/__init__.py +36 -0
- {mcp_agent/core → fast_agent/agents}/agent_types.py +2 -1
- fast_agent/agents/llm_agent.py +217 -0
- fast_agent/agents/llm_decorator.py +486 -0
- mcp_agent/agents/base_agent.py → fast_agent/agents/mcp_agent.py +377 -385
- fast_agent/agents/tool_agent.py +168 -0
- {mcp_agent → fast_agent}/agents/workflow/chain_agent.py +43 -33
- {mcp_agent → fast_agent}/agents/workflow/evaluator_optimizer.py +31 -35
- {mcp_agent → fast_agent}/agents/workflow/iterative_planner.py +56 -47
- {mcp_agent → fast_agent}/agents/workflow/orchestrator_models.py +4 -4
- {mcp_agent → fast_agent}/agents/workflow/parallel_agent.py +34 -41
- {mcp_agent → fast_agent}/agents/workflow/router_agent.py +54 -39
- {mcp_agent → fast_agent}/cli/__main__.py +5 -3
- {mcp_agent → fast_agent}/cli/commands/check_config.py +95 -66
- {mcp_agent → fast_agent}/cli/commands/go.py +20 -11
- {mcp_agent → fast_agent}/cli/commands/quickstart.py +4 -4
- {mcp_agent → fast_agent}/cli/commands/server_helpers.py +1 -1
- {mcp_agent → fast_agent}/cli/commands/setup.py +75 -134
- {mcp_agent → fast_agent}/cli/commands/url_parser.py +9 -8
- {mcp_agent → fast_agent}/cli/main.py +36 -16
- {mcp_agent → fast_agent}/cli/terminal.py +2 -2
- {mcp_agent → fast_agent}/config.py +10 -2
- fast_agent/constants.py +8 -0
- {mcp_agent → fast_agent}/context.py +24 -19
- {mcp_agent → fast_agent}/context_dependent.py +9 -5
- fast_agent/core/__init__.py +52 -0
- {mcp_agent → fast_agent}/core/agent_app.py +39 -36
- fast_agent/core/core_app.py +135 -0
- {mcp_agent → fast_agent}/core/direct_decorators.py +12 -26
- {mcp_agent → fast_agent}/core/direct_factory.py +95 -73
- {mcp_agent → fast_agent/core}/executor/executor.py +4 -5
- {mcp_agent → fast_agent}/core/fastagent.py +32 -32
- fast_agent/core/logging/__init__.py +5 -0
- {mcp_agent → fast_agent/core}/logging/events.py +3 -3
- {mcp_agent → fast_agent/core}/logging/json_serializer.py +1 -1
- {mcp_agent → fast_agent/core}/logging/listeners.py +85 -7
- {mcp_agent → fast_agent/core}/logging/logger.py +7 -7
- {mcp_agent → fast_agent/core}/logging/transport.py +10 -11
- fast_agent/core/prompt.py +9 -0
- {mcp_agent → fast_agent}/core/validation.py +4 -4
- fast_agent/event_progress.py +61 -0
- fast_agent/history/history_exporter.py +44 -0
- {mcp_agent → fast_agent}/human_input/__init__.py +9 -12
- {mcp_agent → fast_agent}/human_input/elicitation_handler.py +26 -8
- {mcp_agent → fast_agent}/human_input/elicitation_state.py +7 -7
- {mcp_agent → fast_agent}/human_input/simple_form.py +6 -4
- {mcp_agent → fast_agent}/human_input/types.py +1 -18
- fast_agent/interfaces.py +228 -0
- fast_agent/llm/__init__.py +9 -0
- mcp_agent/llm/augmented_llm.py → fast_agent/llm/fastagent_llm.py +127 -218
- fast_agent/llm/internal/passthrough.py +137 -0
- mcp_agent/llm/augmented_llm_playback.py → fast_agent/llm/internal/playback.py +29 -25
- mcp_agent/llm/augmented_llm_silent.py → fast_agent/llm/internal/silent.py +10 -17
- fast_agent/llm/internal/slow.py +38 -0
- {mcp_agent → fast_agent}/llm/memory.py +40 -30
- {mcp_agent → fast_agent}/llm/model_database.py +35 -2
- {mcp_agent → fast_agent}/llm/model_factory.py +103 -77
- fast_agent/llm/model_info.py +126 -0
- {mcp_agent/llm/providers → fast_agent/llm/provider/anthropic}/anthropic_utils.py +7 -7
- fast_agent/llm/provider/anthropic/llm_anthropic.py +603 -0
- {mcp_agent/llm/providers → fast_agent/llm/provider/anthropic}/multipart_converter_anthropic.py +79 -86
- {mcp_agent/llm/providers → fast_agent/llm/provider/bedrock}/bedrock_utils.py +3 -1
- mcp_agent/llm/providers/augmented_llm_bedrock.py → fast_agent/llm/provider/bedrock/llm_bedrock.py +833 -717
- {mcp_agent/llm/providers → fast_agent/llm/provider/google}/google_converter.py +66 -14
- fast_agent/llm/provider/google/llm_google_native.py +431 -0
- mcp_agent/llm/providers/augmented_llm_aliyun.py → fast_agent/llm/provider/openai/llm_aliyun.py +6 -7
- mcp_agent/llm/providers/augmented_llm_azure.py → fast_agent/llm/provider/openai/llm_azure.py +4 -4
- mcp_agent/llm/providers/augmented_llm_deepseek.py → fast_agent/llm/provider/openai/llm_deepseek.py +10 -11
- mcp_agent/llm/providers/augmented_llm_generic.py → fast_agent/llm/provider/openai/llm_generic.py +4 -4
- mcp_agent/llm/providers/augmented_llm_google_oai.py → fast_agent/llm/provider/openai/llm_google_oai.py +4 -4
- mcp_agent/llm/providers/augmented_llm_groq.py → fast_agent/llm/provider/openai/llm_groq.py +14 -16
- mcp_agent/llm/providers/augmented_llm_openai.py → fast_agent/llm/provider/openai/llm_openai.py +133 -207
- mcp_agent/llm/providers/augmented_llm_openrouter.py → fast_agent/llm/provider/openai/llm_openrouter.py +6 -6
- mcp_agent/llm/providers/augmented_llm_tensorzero_openai.py → fast_agent/llm/provider/openai/llm_tensorzero_openai.py +17 -16
- mcp_agent/llm/providers/augmented_llm_xai.py → fast_agent/llm/provider/openai/llm_xai.py +6 -6
- {mcp_agent/llm/providers → fast_agent/llm/provider/openai}/multipart_converter_openai.py +125 -63
- {mcp_agent/llm/providers → fast_agent/llm/provider/openai}/openai_multipart.py +12 -12
- {mcp_agent/llm/providers → fast_agent/llm/provider/openai}/openai_utils.py +18 -16
- {mcp_agent → fast_agent}/llm/provider_key_manager.py +2 -2
- {mcp_agent → fast_agent}/llm/provider_types.py +2 -0
- {mcp_agent → fast_agent}/llm/sampling_converter.py +15 -12
- {mcp_agent → fast_agent}/llm/usage_tracking.py +23 -5
- fast_agent/mcp/__init__.py +54 -0
- {mcp_agent → fast_agent}/mcp/elicitation_factory.py +3 -3
- {mcp_agent → fast_agent}/mcp/elicitation_handlers.py +19 -10
- {mcp_agent → fast_agent}/mcp/gen_client.py +3 -3
- fast_agent/mcp/helpers/__init__.py +36 -0
- fast_agent/mcp/helpers/content_helpers.py +183 -0
- {mcp_agent → fast_agent}/mcp/helpers/server_config_helpers.py +8 -8
- {mcp_agent → fast_agent}/mcp/hf_auth.py +25 -23
- fast_agent/mcp/interfaces.py +93 -0
- {mcp_agent → fast_agent}/mcp/logger_textio.py +4 -4
- {mcp_agent → fast_agent}/mcp/mcp_agent_client_session.py +49 -44
- {mcp_agent → fast_agent}/mcp/mcp_aggregator.py +66 -115
- {mcp_agent → fast_agent}/mcp/mcp_connection_manager.py +16 -23
- {mcp_agent/core → fast_agent/mcp}/mcp_content.py +23 -15
- {mcp_agent → fast_agent}/mcp/mime_utils.py +39 -0
- fast_agent/mcp/prompt.py +159 -0
- mcp_agent/mcp/prompt_message_multipart.py → fast_agent/mcp/prompt_message_extended.py +27 -20
- {mcp_agent → fast_agent}/mcp/prompt_render.py +21 -19
- {mcp_agent → fast_agent}/mcp/prompt_serialization.py +46 -46
- fast_agent/mcp/prompts/__main__.py +7 -0
- {mcp_agent → fast_agent}/mcp/prompts/prompt_helpers.py +31 -30
- {mcp_agent → fast_agent}/mcp/prompts/prompt_load.py +8 -8
- {mcp_agent → fast_agent}/mcp/prompts/prompt_server.py +11 -19
- {mcp_agent → fast_agent}/mcp/prompts/prompt_template.py +18 -18
- {mcp_agent → fast_agent}/mcp/resource_utils.py +1 -1
- {mcp_agent → fast_agent}/mcp/sampling.py +31 -26
- {mcp_agent/mcp_server → fast_agent/mcp/server}/__init__.py +1 -1
- {mcp_agent/mcp_server → fast_agent/mcp/server}/agent_server.py +5 -6
- fast_agent/mcp/ui_agent.py +48 -0
- fast_agent/mcp/ui_mixin.py +209 -0
- fast_agent/mcp_server_registry.py +90 -0
- {mcp_agent → fast_agent}/resources/examples/data-analysis/analysis-campaign.py +5 -4
- {mcp_agent → fast_agent}/resources/examples/data-analysis/analysis.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/mcp/elicitations/forms_demo.py +3 -3
- {mcp_agent → fast_agent}/resources/examples/mcp/elicitations/game_character.py +2 -2
- {mcp_agent → fast_agent}/resources/examples/mcp/elicitations/game_character_handler.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/mcp/elicitations/tool_call.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/mcp/state-transfer/agent_one.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/mcp/state-transfer/agent_two.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/researcher/researcher-eval.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/researcher/researcher-imp.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/researcher/researcher.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/tensorzero/agent.py +2 -2
- {mcp_agent → fast_agent}/resources/examples/tensorzero/image_demo.py +3 -3
- {mcp_agent → fast_agent}/resources/examples/tensorzero/simple_agent.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/workflows/chaining.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/workflows/evaluator.py +3 -3
- {mcp_agent → fast_agent}/resources/examples/workflows/human_input.py +5 -3
- {mcp_agent → fast_agent}/resources/examples/workflows/orchestrator.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/workflows/parallel.py +2 -2
- {mcp_agent → fast_agent}/resources/examples/workflows/router.py +5 -2
- fast_agent/resources/setup/.gitignore +24 -0
- fast_agent/resources/setup/agent.py +18 -0
- fast_agent/resources/setup/fastagent.config.yaml +44 -0
- fast_agent/resources/setup/fastagent.secrets.yaml.example +38 -0
- fast_agent/resources/setup/pyproject.toml.tmpl +17 -0
- fast_agent/tools/elicitation.py +369 -0
- fast_agent/types/__init__.py +32 -0
- fast_agent/types/llm_stop_reason.py +77 -0
- fast_agent/ui/__init__.py +38 -0
- fast_agent/ui/console_display.py +1005 -0
- {mcp_agent/human_input → fast_agent/ui}/elicitation_form.py +17 -12
- mcp_agent/human_input/elicitation_forms.py → fast_agent/ui/elicitation_style.py +1 -1
- {mcp_agent/core → fast_agent/ui}/enhanced_prompt.py +96 -25
- {mcp_agent/core → fast_agent/ui}/interactive_prompt.py +330 -125
- fast_agent/ui/mcp_ui_utils.py +224 -0
- {mcp_agent → fast_agent/ui}/progress_display.py +2 -2
- {mcp_agent/logging → fast_agent/ui}/rich_progress.py +4 -4
- {mcp_agent/core → fast_agent/ui}/usage_display.py +3 -8
- {fast_agent_mcp-0.2.58.dist-info → fast_agent_mcp-0.3.1.dist-info}/METADATA +7 -7
- fast_agent_mcp-0.3.1.dist-info/RECORD +203 -0
- fast_agent_mcp-0.3.1.dist-info/entry_points.txt +5 -0
- fast_agent_mcp-0.2.58.dist-info/RECORD +0 -193
- fast_agent_mcp-0.2.58.dist-info/entry_points.txt +0 -6
- mcp_agent/__init__.py +0 -114
- mcp_agent/agents/agent.py +0 -92
- mcp_agent/agents/workflow/__init__.py +0 -1
- mcp_agent/agents/workflow/orchestrator_agent.py +0 -597
- mcp_agent/app.py +0 -175
- mcp_agent/core/__init__.py +0 -26
- mcp_agent/core/prompt.py +0 -191
- mcp_agent/event_progress.py +0 -134
- mcp_agent/human_input/handler.py +0 -81
- mcp_agent/llm/__init__.py +0 -2
- mcp_agent/llm/augmented_llm_passthrough.py +0 -232
- mcp_agent/llm/augmented_llm_slow.py +0 -53
- mcp_agent/llm/providers/__init__.py +0 -8
- mcp_agent/llm/providers/augmented_llm_anthropic.py +0 -718
- mcp_agent/llm/providers/augmented_llm_google_native.py +0 -496
- mcp_agent/llm/providers/sampling_converter_anthropic.py +0 -57
- mcp_agent/llm/providers/sampling_converter_openai.py +0 -26
- mcp_agent/llm/sampling_format_converter.py +0 -37
- mcp_agent/logging/__init__.py +0 -0
- mcp_agent/mcp/__init__.py +0 -50
- mcp_agent/mcp/helpers/__init__.py +0 -25
- mcp_agent/mcp/helpers/content_helpers.py +0 -187
- mcp_agent/mcp/interfaces.py +0 -266
- mcp_agent/mcp/prompts/__init__.py +0 -0
- mcp_agent/mcp/prompts/__main__.py +0 -10
- mcp_agent/mcp_server_registry.py +0 -343
- mcp_agent/tools/tool_definition.py +0 -14
- mcp_agent/ui/console_display.py +0 -790
- mcp_agent/ui/console_display_legacy.py +0 -401
- {mcp_agent → fast_agent}/agents/workflow/orchestrator_prompts.py +0 -0
- {mcp_agent/agents → fast_agent/cli}/__init__.py +0 -0
- {mcp_agent → fast_agent}/cli/constants.py +0 -0
- {mcp_agent → fast_agent}/core/error_handling.py +0 -0
- {mcp_agent → fast_agent}/core/exceptions.py +0 -0
- {mcp_agent/cli → fast_agent/core/executor}/__init__.py +0 -0
- {mcp_agent → fast_agent/core}/executor/task_registry.py +0 -0
- {mcp_agent → fast_agent/core}/executor/workflow_signal.py +0 -0
- {mcp_agent → fast_agent}/human_input/form_fields.py +0 -0
- {mcp_agent → fast_agent}/llm/prompt_utils.py +0 -0
- {mcp_agent/core → fast_agent/llm}/request_params.py +0 -0
- {mcp_agent → fast_agent}/mcp/common.py +0 -0
- {mcp_agent/executor → fast_agent/mcp/prompts}/__init__.py +0 -0
- {mcp_agent → fast_agent}/mcp/prompts/prompt_constants.py +0 -0
- {mcp_agent → fast_agent}/py.typed +0 -0
- {mcp_agent → fast_agent}/resources/examples/data-analysis/fastagent.config.yaml +0 -0
- {mcp_agent → fast_agent}/resources/examples/data-analysis/mount-point/WA_Fn-UseC_-HR-Employee-Attrition.csv +0 -0
- {mcp_agent → fast_agent}/resources/examples/mcp/elicitations/elicitation_account_server.py +0 -0
- {mcp_agent → fast_agent}/resources/examples/mcp/elicitations/elicitation_forms_server.py +0 -0
- {mcp_agent → fast_agent}/resources/examples/mcp/elicitations/elicitation_game_server.py +0 -0
- {mcp_agent → fast_agent}/resources/examples/mcp/elicitations/fastagent.config.yaml +0 -0
- {mcp_agent → fast_agent}/resources/examples/mcp/elicitations/fastagent.secrets.yaml.example +0 -0
- {mcp_agent → fast_agent}/resources/examples/mcp/state-transfer/fastagent.config.yaml +0 -0
- {mcp_agent → fast_agent}/resources/examples/mcp/state-transfer/fastagent.secrets.yaml.example +0 -0
- {mcp_agent → fast_agent}/resources/examples/researcher/fastagent.config.yaml +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/.env.sample +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/Makefile +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/README.md +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/demo_images/clam.jpg +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/demo_images/crab.png +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/demo_images/shrimp.png +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/docker-compose.yml +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/fastagent.config.yaml +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/mcp_server/Dockerfile +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/mcp_server/entrypoint.sh +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/mcp_server/mcp_server.py +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/mcp_server/pyproject.toml +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/tensorzero_config/system_schema.json +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/tensorzero_config/system_template.minijinja +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/tensorzero_config/tensorzero.toml +0 -0
- {mcp_agent → fast_agent}/resources/examples/workflows/fastagent.config.yaml +0 -0
- {mcp_agent → fast_agent}/resources/examples/workflows/graded_report.md +0 -0
- {mcp_agent → fast_agent}/resources/examples/workflows/short_story.md +0 -0
- {mcp_agent → fast_agent}/resources/examples/workflows/short_story.txt +0 -0
- {mcp_agent → fast_agent/ui}/console.py +0 -0
- {mcp_agent/core → fast_agent/ui}/mermaid_utils.py +0 -0
- {fast_agent_mcp-0.2.58.dist-info → fast_agent_mcp-0.3.1.dist-info}/WHEEL +0 -0
- {fast_agent_mcp-0.2.58.dist-info → fast_agent_mcp-0.3.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -2,18 +2,17 @@
|
|
|
2
2
|
Direct AgentApp implementation for interacting with agents without proxies.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
from typing import Dict, List, Optional, Union
|
|
5
|
+
from typing import Dict, List, Mapping, Optional, Union
|
|
6
6
|
|
|
7
7
|
from deprecated import deprecated
|
|
8
8
|
from mcp.types import GetPromptResult, PromptMessage
|
|
9
9
|
from rich import print as rich_print
|
|
10
10
|
|
|
11
|
-
from
|
|
12
|
-
from
|
|
13
|
-
from
|
|
14
|
-
from
|
|
15
|
-
from
|
|
16
|
-
from mcp_agent.progress_display import progress_display
|
|
11
|
+
from fast_agent.agents.agent_types import AgentType
|
|
12
|
+
from fast_agent.interfaces import AgentProtocol
|
|
13
|
+
from fast_agent.types import PromptMessageExtended, RequestParams
|
|
14
|
+
from fast_agent.ui.interactive_prompt import InteractivePrompt
|
|
15
|
+
from fast_agent.ui.progress_display import progress_display
|
|
17
16
|
|
|
18
17
|
|
|
19
18
|
class AgentApp:
|
|
@@ -28,7 +27,7 @@ class AgentApp:
|
|
|
28
27
|
calls to the default agent (the first agent in the container).
|
|
29
28
|
"""
|
|
30
29
|
|
|
31
|
-
def __init__(self, agents: Dict[str,
|
|
30
|
+
def __init__(self, agents: Dict[str, AgentProtocol]) -> None:
|
|
32
31
|
"""
|
|
33
32
|
Initialize the DirectAgentApp.
|
|
34
33
|
|
|
@@ -37,13 +36,13 @@ class AgentApp:
|
|
|
37
36
|
"""
|
|
38
37
|
self._agents = agents
|
|
39
38
|
|
|
40
|
-
def __getitem__(self, key: str) ->
|
|
39
|
+
def __getitem__(self, key: str) -> AgentProtocol:
|
|
41
40
|
"""Allow access to agents using dictionary syntax."""
|
|
42
41
|
if key not in self._agents:
|
|
43
42
|
raise KeyError(f"Agent '{key}' not found")
|
|
44
43
|
return self._agents[key]
|
|
45
44
|
|
|
46
|
-
def __getattr__(self, name: str) ->
|
|
45
|
+
def __getattr__(self, name: str) -> AgentProtocol:
|
|
47
46
|
"""Allow access to agents using attribute syntax."""
|
|
48
47
|
if name in self._agents:
|
|
49
48
|
return self._agents[name]
|
|
@@ -51,7 +50,7 @@ class AgentApp:
|
|
|
51
50
|
|
|
52
51
|
async def __call__(
|
|
53
52
|
self,
|
|
54
|
-
message: Union[str, PromptMessage,
|
|
53
|
+
message: Union[str, PromptMessage, PromptMessageExtended] | None = None,
|
|
55
54
|
agent_name: str | None = None,
|
|
56
55
|
default_prompt: str = "",
|
|
57
56
|
request_params: RequestParams | None = None,
|
|
@@ -62,9 +61,9 @@ class AgentApp:
|
|
|
62
61
|
|
|
63
62
|
Args:
|
|
64
63
|
message: Message content in various formats:
|
|
65
|
-
- String: Converted to a user
|
|
66
|
-
- PromptMessage: Converted to
|
|
67
|
-
-
|
|
64
|
+
- String: Converted to a user PromptMessageExtended
|
|
65
|
+
- PromptMessage: Converted to PromptMessageExtended
|
|
66
|
+
- PromptMessageExtended: Used directly
|
|
68
67
|
agent_name: Optional name of the agent to send to (defaults to first agent)
|
|
69
68
|
default_prompt: Default message to use in interactive prompt mode
|
|
70
69
|
request_params: Optional request parameters including MCP metadata
|
|
@@ -75,11 +74,13 @@ class AgentApp:
|
|
|
75
74
|
if message:
|
|
76
75
|
return await self._agent(agent_name).send(message, request_params)
|
|
77
76
|
|
|
78
|
-
return await self.interactive(
|
|
77
|
+
return await self.interactive(
|
|
78
|
+
agent_name=agent_name, default_prompt=default_prompt, request_params=request_params
|
|
79
|
+
)
|
|
79
80
|
|
|
80
81
|
async def send(
|
|
81
82
|
self,
|
|
82
|
-
message: Union[str, PromptMessage,
|
|
83
|
+
message: Union[str, PromptMessage, PromptMessageExtended],
|
|
83
84
|
agent_name: Optional[str] = None,
|
|
84
85
|
request_params: RequestParams | None = None,
|
|
85
86
|
) -> str:
|
|
@@ -88,9 +89,9 @@ class AgentApp:
|
|
|
88
89
|
|
|
89
90
|
Args:
|
|
90
91
|
message: Message content in various formats:
|
|
91
|
-
- String: Converted to a user
|
|
92
|
-
- PromptMessage: Converted to
|
|
93
|
-
-
|
|
92
|
+
- String: Converted to a user PromptMessageExtended
|
|
93
|
+
- PromptMessage: Converted to PromptMessageExtended
|
|
94
|
+
- PromptMessageExtended: Used directly
|
|
94
95
|
agent_name: Optional name of the agent to send to
|
|
95
96
|
request_params: Optional request parameters including MCP metadata
|
|
96
97
|
|
|
@@ -99,7 +100,7 @@ class AgentApp:
|
|
|
99
100
|
"""
|
|
100
101
|
return await self._agent(agent_name).send(message, request_params)
|
|
101
102
|
|
|
102
|
-
def _agent(self, agent_name: str | None) ->
|
|
103
|
+
def _agent(self, agent_name: str | None) -> AgentProtocol:
|
|
103
104
|
if agent_name:
|
|
104
105
|
if agent_name not in self._agents:
|
|
105
106
|
raise ValueError(f"Agent '{agent_name}' not found")
|
|
@@ -134,7 +135,7 @@ class AgentApp:
|
|
|
134
135
|
prompt, arguments, as_template=as_template
|
|
135
136
|
)
|
|
136
137
|
|
|
137
|
-
async def list_prompts(self,
|
|
138
|
+
async def list_prompts(self, namespace: str | None = None, agent_name: str | None = None):
|
|
138
139
|
"""
|
|
139
140
|
List available prompts for an agent.
|
|
140
141
|
|
|
@@ -148,10 +149,10 @@ class AgentApp:
|
|
|
148
149
|
if not agent_name:
|
|
149
150
|
results = {}
|
|
150
151
|
for agent in self._agents.values():
|
|
151
|
-
curr_prompts = await agent.list_prompts(
|
|
152
|
+
curr_prompts = await agent.list_prompts(namespace=namespace)
|
|
152
153
|
results.update(curr_prompts)
|
|
153
154
|
return results
|
|
154
|
-
return await self._agent(agent_name).list_prompts(
|
|
155
|
+
return await self._agent(agent_name).list_prompts(namespace=namespace)
|
|
155
156
|
|
|
156
157
|
async def get_prompt(
|
|
157
158
|
self,
|
|
@@ -173,12 +174,12 @@ class AgentApp:
|
|
|
173
174
|
GetPromptResult containing the prompt information
|
|
174
175
|
"""
|
|
175
176
|
return await self._agent(agent_name).get_prompt(
|
|
176
|
-
prompt_name=prompt_name, arguments=arguments,
|
|
177
|
+
prompt_name=prompt_name, arguments=arguments, namespace=server_name
|
|
177
178
|
)
|
|
178
179
|
|
|
179
180
|
async def with_resource(
|
|
180
181
|
self,
|
|
181
|
-
prompt_content: Union[str, PromptMessage,
|
|
182
|
+
prompt_content: Union[str, PromptMessage, PromptMessageExtended],
|
|
182
183
|
resource_uri: str,
|
|
183
184
|
server_name: str | None = None,
|
|
184
185
|
agent_name: str | None = None,
|
|
@@ -187,7 +188,7 @@ class AgentApp:
|
|
|
187
188
|
Send a message with an attached MCP resource.
|
|
188
189
|
|
|
189
190
|
Args:
|
|
190
|
-
prompt_content: Content in various formats (String, PromptMessage, or
|
|
191
|
+
prompt_content: Content in various formats (String, PromptMessage, or PromptMessageExtended)
|
|
191
192
|
resource_uri: URI of the resource to retrieve
|
|
192
193
|
server_name: Optional name of the MCP server to retrieve the resource from
|
|
193
194
|
agent_name: Name of the agent to use
|
|
@@ -196,14 +197,14 @@ class AgentApp:
|
|
|
196
197
|
The agent's response as a string
|
|
197
198
|
"""
|
|
198
199
|
return await self._agent(agent_name).with_resource(
|
|
199
|
-
prompt_content=prompt_content, resource_uri=resource_uri,
|
|
200
|
+
prompt_content=prompt_content, resource_uri=resource_uri, namespace=server_name
|
|
200
201
|
)
|
|
201
202
|
|
|
202
203
|
async def list_resources(
|
|
203
204
|
self,
|
|
204
205
|
server_name: str | None = None,
|
|
205
206
|
agent_name: str | None = None,
|
|
206
|
-
) ->
|
|
207
|
+
) -> Mapping[str, List[str]]:
|
|
207
208
|
"""
|
|
208
209
|
List available resources from one or all servers.
|
|
209
210
|
|
|
@@ -214,7 +215,7 @@ class AgentApp:
|
|
|
214
215
|
Returns:
|
|
215
216
|
Dictionary mapping server names to lists of resource URIs
|
|
216
217
|
"""
|
|
217
|
-
return await self._agent(agent_name).list_resources(
|
|
218
|
+
return await self._agent(agent_name).list_resources(namespace=server_name)
|
|
218
219
|
|
|
219
220
|
async def get_resource(
|
|
220
221
|
self,
|
|
@@ -234,20 +235,22 @@ class AgentApp:
|
|
|
234
235
|
ReadResourceResult object containing the resource content
|
|
235
236
|
"""
|
|
236
237
|
return await self._agent(agent_name).get_resource(
|
|
237
|
-
resource_uri=resource_uri,
|
|
238
|
+
resource_uri=resource_uri, namespace=server_name
|
|
238
239
|
)
|
|
239
240
|
|
|
240
241
|
@deprecated
|
|
241
242
|
async def prompt(
|
|
242
|
-
self,
|
|
243
|
-
agent_name: str | None = None,
|
|
243
|
+
self,
|
|
244
|
+
agent_name: str | None = None,
|
|
244
245
|
default_prompt: str = "",
|
|
245
|
-
request_params: RequestParams | None = None
|
|
246
|
+
request_params: RequestParams | None = None,
|
|
246
247
|
) -> str:
|
|
247
248
|
"""
|
|
248
249
|
Deprecated - use interactive() instead.
|
|
249
250
|
"""
|
|
250
|
-
return await self.interactive(
|
|
251
|
+
return await self.interactive(
|
|
252
|
+
agent_name=agent_name, default_prompt=default_prompt, request_params=request_params
|
|
253
|
+
)
|
|
251
254
|
|
|
252
255
|
async def interactive(
|
|
253
256
|
self,
|
|
@@ -279,7 +282,7 @@ class AgentApp:
|
|
|
279
282
|
target_name = None
|
|
280
283
|
for agent in self._agents.values():
|
|
281
284
|
if agent.config.default:
|
|
282
|
-
target_name = agent.
|
|
285
|
+
target_name = agent.name
|
|
283
286
|
break
|
|
284
287
|
|
|
285
288
|
if not target_name:
|
|
@@ -303,7 +306,7 @@ class AgentApp:
|
|
|
303
306
|
if pretty_print_parallel:
|
|
304
307
|
agent = self._agents.get(agent_name)
|
|
305
308
|
if agent and agent.agent_type == AgentType.PARALLEL:
|
|
306
|
-
from
|
|
309
|
+
from fast_agent.ui.console_display import ConsoleDisplay
|
|
307
310
|
|
|
308
311
|
display = ConsoleDisplay(config=None)
|
|
309
312
|
display.show_parallel_results(agent)
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
from contextlib import asynccontextmanager
|
|
5
|
+
from typing import TYPE_CHECKING, Optional, TypeVar
|
|
6
|
+
|
|
7
|
+
from fast_agent.core.logging.logger import get_logger
|
|
8
|
+
from fast_agent.event_progress import ProgressAction
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
# Only imported for type checking to avoid circular imports at runtime
|
|
12
|
+
from fast_agent.config import Settings
|
|
13
|
+
from fast_agent.context import Context
|
|
14
|
+
from fast_agent.core.executor.workflow_signal import SignalWaitCallback
|
|
15
|
+
|
|
16
|
+
R = TypeVar("R")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Core:
|
|
20
|
+
"""
|
|
21
|
+
fast-agent core. handles application settings, config and context management.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
name: str = "fast-agent",
|
|
27
|
+
settings: Optional[Settings] | str = None,
|
|
28
|
+
signal_notification: Optional[SignalWaitCallback] = None,
|
|
29
|
+
) -> None:
|
|
30
|
+
"""
|
|
31
|
+
Initialize the core.
|
|
32
|
+
Args:
|
|
33
|
+
name:
|
|
34
|
+
settings: If unspecified, the settings are loaded from fastagent.config.yaml.
|
|
35
|
+
If this is a string, it is treated as the path to the config file to load.
|
|
36
|
+
signal_notification: Callback for getting notified on workflow signals/events.
|
|
37
|
+
"""
|
|
38
|
+
self.name = name
|
|
39
|
+
|
|
40
|
+
# We use these to initialize the context in initialize()
|
|
41
|
+
self._config_or_path = settings
|
|
42
|
+
self._signal_notification = signal_notification
|
|
43
|
+
|
|
44
|
+
self._logger = None
|
|
45
|
+
# Use forward reference for type to avoid runtime import
|
|
46
|
+
self._context: Optional["Context"] = None
|
|
47
|
+
self._initialized = False
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def context(self) -> "Context":
|
|
51
|
+
if self._context is None:
|
|
52
|
+
raise RuntimeError(
|
|
53
|
+
"Core not initialized, please call initialize() first, or use async with app.run()."
|
|
54
|
+
)
|
|
55
|
+
return self._context
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
def config(self):
|
|
59
|
+
return self.context.config
|
|
60
|
+
|
|
61
|
+
@property
|
|
62
|
+
def server_registry(self):
|
|
63
|
+
return self.context.server_registry
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def logger(self):
|
|
67
|
+
if self._logger is None:
|
|
68
|
+
self._logger = get_logger(f"fast_agent.{self.name}")
|
|
69
|
+
return self._logger
|
|
70
|
+
|
|
71
|
+
async def initialize(self) -> None:
|
|
72
|
+
"""Initialize the fast-agent core. Sets up context (and therefore logging and loading settings)."""
|
|
73
|
+
if self._initialized:
|
|
74
|
+
return
|
|
75
|
+
|
|
76
|
+
# Import here to avoid circular imports during module initialization
|
|
77
|
+
from fast_agent import context as _context_mod
|
|
78
|
+
|
|
79
|
+
self._context = await _context_mod.initialize_context(
|
|
80
|
+
self._config_or_path, store_globally=True
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
# Set the properties that were passed in the constructor
|
|
84
|
+
self._context.signal_notification = self._signal_notification
|
|
85
|
+
# Note: upstream_session support removed for now
|
|
86
|
+
|
|
87
|
+
self._initialized = True
|
|
88
|
+
self.logger.info(
|
|
89
|
+
"fast-agent initialized",
|
|
90
|
+
data={
|
|
91
|
+
"progress_action": "Running",
|
|
92
|
+
"target": self.name or "mcp_application",
|
|
93
|
+
"agent_name": self.name or "fast-agent core",
|
|
94
|
+
},
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
async def cleanup(self) -> None:
|
|
98
|
+
"""Cleanup application resources."""
|
|
99
|
+
if not self._initialized:
|
|
100
|
+
return
|
|
101
|
+
|
|
102
|
+
self.logger.info(
|
|
103
|
+
"fast-agent cleanup",
|
|
104
|
+
data={
|
|
105
|
+
"progress_action": ProgressAction.FINISHED,
|
|
106
|
+
"target": self.name or "fast-agent",
|
|
107
|
+
"agent_name": self.name or "fast-agent core",
|
|
108
|
+
},
|
|
109
|
+
)
|
|
110
|
+
try:
|
|
111
|
+
# Import here to avoid circular imports during module initialization
|
|
112
|
+
from fast_agent import context as _context_mod
|
|
113
|
+
|
|
114
|
+
await _context_mod.cleanup_context()
|
|
115
|
+
except asyncio.CancelledError:
|
|
116
|
+
self.logger.debug("Cleanup cancelled error during shutdown")
|
|
117
|
+
|
|
118
|
+
self._context = None
|
|
119
|
+
self._initialized = False
|
|
120
|
+
|
|
121
|
+
@asynccontextmanager
|
|
122
|
+
async def run(self):
|
|
123
|
+
"""
|
|
124
|
+
Use core for context management
|
|
125
|
+
|
|
126
|
+
Example:
|
|
127
|
+
async with core.run() as running_app:
|
|
128
|
+
# App is initialized here
|
|
129
|
+
pass
|
|
130
|
+
"""
|
|
131
|
+
await self.initialize()
|
|
132
|
+
try:
|
|
133
|
+
yield self
|
|
134
|
+
finally:
|
|
135
|
+
await self.cleanup()
|
|
@@ -4,7 +4,6 @@ These decorators provide type-safe function signatures and IDE support
|
|
|
4
4
|
for creating agents in the DirectFastAgent framework.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
|
-
import inspect
|
|
8
7
|
from functools import wraps
|
|
9
8
|
from pathlib import Path
|
|
10
9
|
from typing import (
|
|
@@ -17,27 +16,25 @@ from typing import (
|
|
|
17
16
|
ParamSpec,
|
|
18
17
|
Protocol,
|
|
19
18
|
TypeVar,
|
|
20
|
-
Union,
|
|
21
19
|
cast,
|
|
22
20
|
)
|
|
23
21
|
|
|
24
22
|
from mcp.client.session import ElicitationFnT
|
|
25
23
|
from pydantic import AnyUrl
|
|
26
24
|
|
|
27
|
-
from
|
|
28
|
-
from
|
|
29
|
-
from
|
|
25
|
+
from fast_agent.agents.agent_types import AgentConfig, AgentType
|
|
26
|
+
from fast_agent.agents.workflow.iterative_planner import ITERATIVE_PLAN_SYSTEM_PROMPT_TEMPLATE
|
|
27
|
+
from fast_agent.agents.workflow.router_agent import (
|
|
30
28
|
ROUTING_SYSTEM_INSTRUCTION,
|
|
31
29
|
)
|
|
32
|
-
from
|
|
33
|
-
from mcp_agent.core.request_params import RequestParams
|
|
30
|
+
from fast_agent.types import RequestParams
|
|
34
31
|
|
|
35
32
|
# Type variables for the decorated function
|
|
36
33
|
P = ParamSpec("P") # Parameters
|
|
37
|
-
R = TypeVar("R") # Return type
|
|
34
|
+
R = TypeVar("R", covariant=True) # Return type
|
|
38
35
|
|
|
39
36
|
# Type for agent functions - can be either async or sync
|
|
40
|
-
AgentCallable = Callable[P,
|
|
37
|
+
AgentCallable = Callable[P, Awaitable[R]]
|
|
41
38
|
|
|
42
39
|
|
|
43
40
|
# Protocol for decorated agent functions
|
|
@@ -47,7 +44,7 @@ class DecoratedAgentProtocol(Protocol[P, R]):
|
|
|
47
44
|
_agent_type: AgentType
|
|
48
45
|
_agent_config: AgentConfig
|
|
49
46
|
|
|
50
|
-
def __call__(self, *args: P.args, **kwargs: P.kwargs) ->
|
|
47
|
+
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> Awaitable[R]: ...
|
|
51
48
|
|
|
52
49
|
|
|
53
50
|
# Protocol for orchestrator functions
|
|
@@ -207,21 +204,10 @@ def _decorator_impl(
|
|
|
207
204
|
"""
|
|
208
205
|
|
|
209
206
|
def decorator(func: AgentCallable[P, R]) -> DecoratedAgentProtocol[P, R]:
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
@wraps(func)
|
|
216
|
-
async def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
|
|
217
|
-
# Call the original function
|
|
218
|
-
return await func(*args, **kwargs)
|
|
219
|
-
else:
|
|
220
|
-
|
|
221
|
-
@wraps(func)
|
|
222
|
-
def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
|
|
223
|
-
# Call the original function
|
|
224
|
-
return func(*args, **kwargs)
|
|
207
|
+
@wraps(func)
|
|
208
|
+
def wrapper(*args: P.args, **kwargs: P.kwargs) -> Awaitable[R]:
|
|
209
|
+
# Call the original function
|
|
210
|
+
return func(*args, **kwargs)
|
|
225
211
|
|
|
226
212
|
# Create agent configuration
|
|
227
213
|
config = AgentConfig(
|
|
@@ -597,7 +583,7 @@ def chain(
|
|
|
597
583
|
"""
|
|
598
584
|
# Validate sequence is not empty
|
|
599
585
|
if not sequence:
|
|
600
|
-
from
|
|
586
|
+
from fast_agent.core.exceptions import AgentConfigError
|
|
601
587
|
|
|
602
588
|
raise AgentConfigError(f"Chain '{name}' requires at least one agent in the sequence")
|
|
603
589
|
|