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
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Helper modules for working with MCP content.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from .content_helpers import (
|
|
6
|
-
get_image_data,
|
|
7
|
-
get_resource_text,
|
|
8
|
-
get_resource_uri,
|
|
9
|
-
get_text,
|
|
10
|
-
is_image_content,
|
|
11
|
-
is_resource_content,
|
|
12
|
-
is_resource_link,
|
|
13
|
-
is_text_content,
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
__all__ = [
|
|
17
|
-
"get_text",
|
|
18
|
-
"get_image_data",
|
|
19
|
-
"get_resource_uri",
|
|
20
|
-
"is_text_content",
|
|
21
|
-
"is_image_content",
|
|
22
|
-
"is_resource_content",
|
|
23
|
-
"is_resource_link",
|
|
24
|
-
"get_resource_text",
|
|
25
|
-
]
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Helper functions for working with content objects.
|
|
3
|
-
|
|
4
|
-
These utilities simplify extracting content from content structures
|
|
5
|
-
without repetitive type checking.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from typing import Optional, Union
|
|
9
|
-
|
|
10
|
-
from mcp.types import (
|
|
11
|
-
BlobResourceContents,
|
|
12
|
-
ContentBlock,
|
|
13
|
-
EmbeddedResource,
|
|
14
|
-
ImageContent,
|
|
15
|
-
ReadResourceResult,
|
|
16
|
-
ResourceLink,
|
|
17
|
-
TextContent,
|
|
18
|
-
TextResourceContents,
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def get_text(content: ContentBlock) -> Optional[str]:
|
|
23
|
-
"""
|
|
24
|
-
Extract text content from a content object if available.
|
|
25
|
-
|
|
26
|
-
Args:
|
|
27
|
-
content: A content object ContentBlock
|
|
28
|
-
|
|
29
|
-
Returns:
|
|
30
|
-
The text content as a string or None if not a text content
|
|
31
|
-
"""
|
|
32
|
-
if isinstance(content, TextContent):
|
|
33
|
-
return content.text
|
|
34
|
-
|
|
35
|
-
if isinstance(content, TextResourceContents):
|
|
36
|
-
return content.text
|
|
37
|
-
|
|
38
|
-
if isinstance(content, EmbeddedResource):
|
|
39
|
-
if isinstance(content.resource, TextResourceContents):
|
|
40
|
-
return content.resource.text
|
|
41
|
-
|
|
42
|
-
return None
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def get_image_data(content: ContentBlock) -> Optional[str]:
|
|
46
|
-
"""
|
|
47
|
-
Extract image data from a content object if available.
|
|
48
|
-
|
|
49
|
-
Args:
|
|
50
|
-
content: A content object ContentBlock
|
|
51
|
-
|
|
52
|
-
Returns:
|
|
53
|
-
The image data as a base64 string or None if not an image content
|
|
54
|
-
"""
|
|
55
|
-
if isinstance(content, ImageContent):
|
|
56
|
-
return content.data
|
|
57
|
-
|
|
58
|
-
if isinstance(content, EmbeddedResource):
|
|
59
|
-
if isinstance(content.resource, BlobResourceContents):
|
|
60
|
-
# This assumes the blob might be an image, which isn't always true
|
|
61
|
-
# Consider checking the mimeType if needed
|
|
62
|
-
return content.resource.blob
|
|
63
|
-
|
|
64
|
-
return None
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
def get_resource_uri(content: ContentBlock) -> Optional[str]:
|
|
68
|
-
"""
|
|
69
|
-
Extract resource URI from an EmbeddedResource if available.
|
|
70
|
-
|
|
71
|
-
Args:
|
|
72
|
-
content: A content object ContentBlock
|
|
73
|
-
|
|
74
|
-
Returns:
|
|
75
|
-
The resource URI as a string or None if not an embedded resource
|
|
76
|
-
"""
|
|
77
|
-
if isinstance(content, EmbeddedResource):
|
|
78
|
-
return str(content.resource.uri)
|
|
79
|
-
|
|
80
|
-
return None
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
def is_text_content(content: ContentBlock) -> bool:
|
|
84
|
-
"""
|
|
85
|
-
Check if the content is text content.
|
|
86
|
-
|
|
87
|
-
Args:
|
|
88
|
-
content: A content object ContentBlock
|
|
89
|
-
|
|
90
|
-
Returns:
|
|
91
|
-
True if the content is TextContent, False otherwise
|
|
92
|
-
"""
|
|
93
|
-
return isinstance(content, TextContent) or isinstance(content, TextResourceContents)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
def is_image_content(content: Union[TextContent, ImageContent, EmbeddedResource]) -> bool:
|
|
97
|
-
"""
|
|
98
|
-
Check if the content is image content.
|
|
99
|
-
|
|
100
|
-
Args:
|
|
101
|
-
content: A content object ContentBlock
|
|
102
|
-
|
|
103
|
-
Returns:
|
|
104
|
-
True if the content is ImageContent, False otherwise
|
|
105
|
-
"""
|
|
106
|
-
return isinstance(content, ImageContent)
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
def is_resource_content(content: ContentBlock) -> bool:
|
|
110
|
-
"""
|
|
111
|
-
Check if the content is an embedded resource.
|
|
112
|
-
|
|
113
|
-
Args:
|
|
114
|
-
content: A content object ContentBlock
|
|
115
|
-
|
|
116
|
-
Returns:
|
|
117
|
-
True if the content is EmbeddedResource, False otherwise
|
|
118
|
-
"""
|
|
119
|
-
return isinstance(content, EmbeddedResource)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
def is_resource_link(content: ContentBlock) -> bool:
|
|
123
|
-
"""
|
|
124
|
-
Check if the content is an embedded resource.
|
|
125
|
-
|
|
126
|
-
Args:
|
|
127
|
-
content: A ContentBlock object
|
|
128
|
-
|
|
129
|
-
Returns:
|
|
130
|
-
True if the content is ResourceLink, False otherwise
|
|
131
|
-
"""
|
|
132
|
-
return isinstance(content, ResourceLink)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
def get_resource_text(result: ReadResourceResult, index: int = 0) -> Optional[str]:
|
|
136
|
-
"""
|
|
137
|
-
Extract text content from a ReadResourceResult at the specified index.
|
|
138
|
-
|
|
139
|
-
Args:
|
|
140
|
-
result: A ReadResourceResult from an MCP resource read operation
|
|
141
|
-
index: Index of the content item to extract text from (default: 0)
|
|
142
|
-
|
|
143
|
-
Returns:
|
|
144
|
-
The text content as a string or None if not available or not text content
|
|
145
|
-
|
|
146
|
-
Raises:
|
|
147
|
-
IndexError: If the index is out of bounds for the contents list
|
|
148
|
-
"""
|
|
149
|
-
if index >= len(result.contents):
|
|
150
|
-
raise IndexError(
|
|
151
|
-
f"Index {index} out of bounds for contents list of length {len(result.contents)}"
|
|
152
|
-
)
|
|
153
|
-
|
|
154
|
-
content = result.contents[index]
|
|
155
|
-
if isinstance(content, TextResourceContents):
|
|
156
|
-
return content.text
|
|
157
|
-
|
|
158
|
-
return None
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
def split_thinking_content(message: str) -> tuple[Optional[str], str]:
|
|
162
|
-
"""
|
|
163
|
-
Split a message into thinking and content parts.
|
|
164
|
-
|
|
165
|
-
Extracts content between <thinking> tags and returns it along with the remaining content.
|
|
166
|
-
|
|
167
|
-
Args:
|
|
168
|
-
message: A string that may contain a <thinking>...</thinking> block followed by content
|
|
169
|
-
|
|
170
|
-
Returns:
|
|
171
|
-
A tuple of (thinking_content, main_content) where:
|
|
172
|
-
- thinking_content: The content inside <thinking> tags, or None if not found/parsing fails
|
|
173
|
-
- main_content: The content after the thinking block, or the entire message if no thinking block
|
|
174
|
-
"""
|
|
175
|
-
import re
|
|
176
|
-
|
|
177
|
-
# Pattern to match <thinking>...</thinking> at the start of the message
|
|
178
|
-
pattern = r"^<think>(.*?)</think>\s*(.*)$"
|
|
179
|
-
match = re.match(pattern, message, re.DOTALL)
|
|
180
|
-
|
|
181
|
-
if match:
|
|
182
|
-
thinking_content = match.group(1).strip()
|
|
183
|
-
main_content = match.group(2).strip()
|
|
184
|
-
return (thinking_content, main_content)
|
|
185
|
-
else:
|
|
186
|
-
# No thinking block found or parsing failed
|
|
187
|
-
return (None, message)
|
mcp_agent/mcp/interfaces.py
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Interface definitions to prevent circular imports.
|
|
3
|
-
This module defines protocols (interfaces) that can be used to break circular dependencies.
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
from datetime import timedelta
|
|
7
|
-
from typing import (
|
|
8
|
-
TYPE_CHECKING,
|
|
9
|
-
Any,
|
|
10
|
-
AsyncContextManager,
|
|
11
|
-
Callable,
|
|
12
|
-
Dict,
|
|
13
|
-
List,
|
|
14
|
-
Mapping,
|
|
15
|
-
Optional,
|
|
16
|
-
Protocol,
|
|
17
|
-
Tuple,
|
|
18
|
-
Type,
|
|
19
|
-
TypeVar,
|
|
20
|
-
Union,
|
|
21
|
-
runtime_checkable,
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
from a2a.types import AgentCard
|
|
25
|
-
from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream
|
|
26
|
-
from deprecated import deprecated
|
|
27
|
-
from mcp import ClientSession
|
|
28
|
-
from mcp.types import GetPromptResult, Prompt, PromptMessage, ReadResourceResult, Tool
|
|
29
|
-
from pydantic import BaseModel
|
|
30
|
-
|
|
31
|
-
from mcp_agent.core.agent_types import AgentType
|
|
32
|
-
from mcp_agent.core.request_params import RequestParams
|
|
33
|
-
from mcp_agent.mcp.prompt_message_multipart import PromptMessageMultipart
|
|
34
|
-
|
|
35
|
-
if TYPE_CHECKING:
|
|
36
|
-
from mcp_agent.llm.usage_tracking import UsageAccumulator
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
__all__ = [
|
|
40
|
-
"MCPConnectionManagerProtocol",
|
|
41
|
-
"ServerRegistryProtocol",
|
|
42
|
-
"ServerConnection",
|
|
43
|
-
"AugmentedLLMProtocol",
|
|
44
|
-
"AgentProtocol",
|
|
45
|
-
"ModelFactoryClassProtocol",
|
|
46
|
-
"ModelT",
|
|
47
|
-
]
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
@runtime_checkable
|
|
51
|
-
class MCPConnectionManagerProtocol(Protocol):
|
|
52
|
-
"""Protocol for MCPConnectionManager functionality needed by ServerRegistry."""
|
|
53
|
-
|
|
54
|
-
async def get_server(
|
|
55
|
-
self,
|
|
56
|
-
server_name: str,
|
|
57
|
-
client_session_factory: Optional[
|
|
58
|
-
Callable[
|
|
59
|
-
[
|
|
60
|
-
MemoryObjectReceiveStream,
|
|
61
|
-
MemoryObjectSendStream,
|
|
62
|
-
Optional[timedelta],
|
|
63
|
-
],
|
|
64
|
-
ClientSession,
|
|
65
|
-
]
|
|
66
|
-
] = None,
|
|
67
|
-
) -> "ServerConnection": ...
|
|
68
|
-
|
|
69
|
-
async def disconnect_server(self, server_name: str) -> None: ...
|
|
70
|
-
|
|
71
|
-
async def disconnect_all_servers(self) -> None: ...
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
@runtime_checkable
|
|
75
|
-
class ServerRegistryProtocol(Protocol):
|
|
76
|
-
"""Protocol defining the minimal interface of ServerRegistry needed by gen_client."""
|
|
77
|
-
|
|
78
|
-
@property
|
|
79
|
-
def connection_manager(self) -> MCPConnectionManagerProtocol: ...
|
|
80
|
-
|
|
81
|
-
def initialize_server(
|
|
82
|
-
self,
|
|
83
|
-
server_name: str,
|
|
84
|
-
client_session_factory: Optional[
|
|
85
|
-
Callable[
|
|
86
|
-
[
|
|
87
|
-
MemoryObjectReceiveStream,
|
|
88
|
-
MemoryObjectSendStream,
|
|
89
|
-
Optional[timedelta],
|
|
90
|
-
],
|
|
91
|
-
ClientSession,
|
|
92
|
-
]
|
|
93
|
-
] = None,
|
|
94
|
-
init_hook: Optional[Callable] = None,
|
|
95
|
-
) -> AsyncContextManager[ClientSession]:
|
|
96
|
-
"""Initialize a server and yield a client session."""
|
|
97
|
-
...
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
class ServerConnection(Protocol):
|
|
101
|
-
"""Protocol for server connection objects returned by MCPConnectionManager."""
|
|
102
|
-
|
|
103
|
-
@property
|
|
104
|
-
def session(self) -> ClientSession: ...
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
ModelT = TypeVar("ModelT", bound=BaseModel)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
class AugmentedLLMProtocol(Protocol):
|
|
111
|
-
"""Protocol defining the interface for augmented LLMs"""
|
|
112
|
-
|
|
113
|
-
async def structured(
|
|
114
|
-
self,
|
|
115
|
-
multipart_messages: List[Union[PromptMessageMultipart, PromptMessage]],
|
|
116
|
-
model: Type[ModelT],
|
|
117
|
-
request_params: RequestParams | None = None,
|
|
118
|
-
) -> Tuple[ModelT | None, PromptMessageMultipart]:
|
|
119
|
-
"""Apply the prompt and return the result as a Pydantic model, or None if coercion fails"""
|
|
120
|
-
...
|
|
121
|
-
|
|
122
|
-
async def generate(
|
|
123
|
-
self,
|
|
124
|
-
multipart_messages: List[Union[PromptMessageMultipart, PromptMessage]],
|
|
125
|
-
request_params: RequestParams | None = None,
|
|
126
|
-
) -> PromptMessageMultipart:
|
|
127
|
-
"""
|
|
128
|
-
Apply a list of PromptMessageMultipart messages directly to the LLM.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
Args:
|
|
132
|
-
multipart_messages: List of PromptMessageMultipart objects
|
|
133
|
-
request_params: Optional parameters to configure the LLM request
|
|
134
|
-
|
|
135
|
-
Returns:
|
|
136
|
-
A PromptMessageMultipart containing the Assistant response, including Tool Content
|
|
137
|
-
"""
|
|
138
|
-
...
|
|
139
|
-
|
|
140
|
-
async def apply_prompt_template(
|
|
141
|
-
self, prompt_result: "GetPromptResult", prompt_name: str
|
|
142
|
-
) -> str:
|
|
143
|
-
"""
|
|
144
|
-
Apply a prompt template as persistent context that will be included in all future conversations.
|
|
145
|
-
|
|
146
|
-
Args:
|
|
147
|
-
prompt_result: The GetPromptResult containing prompt messages
|
|
148
|
-
prompt_name: The name of the prompt being applied
|
|
149
|
-
|
|
150
|
-
Returns:
|
|
151
|
-
String representation of the assistant's response if generated
|
|
152
|
-
"""
|
|
153
|
-
...
|
|
154
|
-
|
|
155
|
-
@property
|
|
156
|
-
def message_history(self) -> List[PromptMessageMultipart]:
|
|
157
|
-
"""
|
|
158
|
-
Return the LLM's message history as PromptMessageMultipart objects.
|
|
159
|
-
|
|
160
|
-
Returns:
|
|
161
|
-
List of PromptMessageMultipart objects representing the conversation history
|
|
162
|
-
"""
|
|
163
|
-
...
|
|
164
|
-
|
|
165
|
-
usage_accumulator: "UsageAccumulator"
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
class AgentProtocol(AugmentedLLMProtocol, Protocol):
|
|
169
|
-
"""Protocol defining the standard agent interface"""
|
|
170
|
-
|
|
171
|
-
name: str
|
|
172
|
-
|
|
173
|
-
@property
|
|
174
|
-
def agent_type(self) -> AgentType:
|
|
175
|
-
"""Return the type of this agent"""
|
|
176
|
-
...
|
|
177
|
-
|
|
178
|
-
async def __call__(self, message: Union[str, PromptMessage, PromptMessageMultipart]) -> str:
|
|
179
|
-
"""Make the agent callable for sending messages directly."""
|
|
180
|
-
...
|
|
181
|
-
|
|
182
|
-
async def send(self, message: Union[str, PromptMessage, PromptMessageMultipart]) -> str:
|
|
183
|
-
"""Send a message to the agent and get a response"""
|
|
184
|
-
...
|
|
185
|
-
|
|
186
|
-
async def apply_prompt(
|
|
187
|
-
self,
|
|
188
|
-
prompt: Union[str, "GetPromptResult"],
|
|
189
|
-
arguments: Dict[str, str] | None = None,
|
|
190
|
-
as_template: bool = False,
|
|
191
|
-
) -> str:
|
|
192
|
-
"""Apply an MCP prompt template by name or GetPromptResult object"""
|
|
193
|
-
...
|
|
194
|
-
|
|
195
|
-
async def get_prompt(
|
|
196
|
-
self,
|
|
197
|
-
prompt_name: str,
|
|
198
|
-
arguments: Dict[str, str] | None = None,
|
|
199
|
-
server_name: str | None = None,
|
|
200
|
-
) -> GetPromptResult: ...
|
|
201
|
-
|
|
202
|
-
async def list_prompts(self, server_name: str | None = None) -> Mapping[str, List[Prompt]]: ...
|
|
203
|
-
|
|
204
|
-
async def list_resources(self, server_name: str | None = None) -> Mapping[str, List[str]]: ...
|
|
205
|
-
|
|
206
|
-
async def list_mcp_tools(self, server_name: str | None = None) -> Mapping[str, List[Tool]]: ...
|
|
207
|
-
|
|
208
|
-
async def get_resource(
|
|
209
|
-
self, resource_uri: str, server_name: str | None = None
|
|
210
|
-
) -> ReadResourceResult:
|
|
211
|
-
"""Get a resource from a specific server or search all servers"""
|
|
212
|
-
...
|
|
213
|
-
|
|
214
|
-
@deprecated
|
|
215
|
-
async def generate_str(self, message: str, request_params: RequestParams | None = None) -> str:
|
|
216
|
-
"""Generate a response. Deprecated: Use send(), generate() or structured() instead"""
|
|
217
|
-
...
|
|
218
|
-
|
|
219
|
-
@deprecated
|
|
220
|
-
async def prompt(self, default_prompt: str = "") -> str:
|
|
221
|
-
"""Start an interactive prompt session with the agent. Deprecated. Use agent_app.interactive() instead."""
|
|
222
|
-
...
|
|
223
|
-
|
|
224
|
-
async def with_resource(
|
|
225
|
-
self,
|
|
226
|
-
prompt_content: Union[str, PromptMessage, PromptMessageMultipart],
|
|
227
|
-
resource_uri: str,
|
|
228
|
-
server_name: str | None = None,
|
|
229
|
-
) -> str:
|
|
230
|
-
"""Send a message with an attached MCP resource"""
|
|
231
|
-
...
|
|
232
|
-
|
|
233
|
-
async def agent_card(self) -> AgentCard:
|
|
234
|
-
"""Return an A2A Agent Card for this Agent"""
|
|
235
|
-
...
|
|
236
|
-
|
|
237
|
-
async def initialize(self) -> None:
|
|
238
|
-
"""Initialize the agent and connect to MCP servers"""
|
|
239
|
-
...
|
|
240
|
-
|
|
241
|
-
async def shutdown(self) -> None:
|
|
242
|
-
"""Shut down the agent and close connections"""
|
|
243
|
-
...
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
class ModelFactoryClassProtocol(Protocol):
|
|
247
|
-
"""
|
|
248
|
-
Protocol defining the minimal interface of the ModelFactory class needed by sampling.
|
|
249
|
-
This allows sampling.py to depend on this protocol rather than the concrete ModelFactory class.
|
|
250
|
-
"""
|
|
251
|
-
|
|
252
|
-
@classmethod
|
|
253
|
-
def create_factory(
|
|
254
|
-
cls, model_string: str, request_params: Optional[RequestParams] = None
|
|
255
|
-
) -> Callable[..., Any]:
|
|
256
|
-
"""
|
|
257
|
-
Creates a factory function that can be used to construct an LLM instance.
|
|
258
|
-
|
|
259
|
-
Args:
|
|
260
|
-
model_string: The model specification string
|
|
261
|
-
request_params: Optional parameters to configure LLM behavior
|
|
262
|
-
|
|
263
|
-
Returns:
|
|
264
|
-
A factory function that can create an LLM instance
|
|
265
|
-
"""
|
|
266
|
-
...
|
|
File without changes
|