fast-agent-mcp 0.1.11__py3-none-any.whl → 0.1.13__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_mcp-0.1.11.dist-info → fast_agent_mcp-0.1.13.dist-info}/METADATA +1 -1
- fast_agent_mcp-0.1.13.dist-info/RECORD +164 -0
- mcp_agent/agents/agent.py +37 -102
- mcp_agent/app.py +16 -27
- mcp_agent/cli/commands/bootstrap.py +22 -52
- mcp_agent/cli/commands/config.py +4 -4
- mcp_agent/cli/commands/setup.py +11 -26
- mcp_agent/cli/main.py +6 -9
- mcp_agent/cli/terminal.py +2 -2
- mcp_agent/config.py +1 -5
- mcp_agent/context.py +13 -26
- mcp_agent/context_dependent.py +3 -7
- mcp_agent/core/agent_app.py +46 -122
- mcp_agent/core/agent_types.py +29 -2
- mcp_agent/core/agent_utils.py +3 -5
- mcp_agent/core/decorators.py +6 -14
- mcp_agent/core/enhanced_prompt.py +25 -52
- mcp_agent/core/error_handling.py +1 -1
- mcp_agent/core/exceptions.py +8 -8
- mcp_agent/core/factory.py +30 -72
- mcp_agent/core/fastagent.py +48 -88
- mcp_agent/core/mcp_content.py +10 -19
- mcp_agent/core/prompt.py +8 -15
- mcp_agent/core/proxies.py +34 -25
- mcp_agent/core/request_params.py +46 -0
- mcp_agent/core/types.py +6 -6
- mcp_agent/core/validation.py +16 -16
- mcp_agent/executor/decorator_registry.py +11 -23
- mcp_agent/executor/executor.py +8 -17
- mcp_agent/executor/task_registry.py +2 -4
- mcp_agent/executor/temporal.py +28 -74
- mcp_agent/executor/workflow.py +3 -5
- mcp_agent/executor/workflow_signal.py +17 -29
- mcp_agent/human_input/handler.py +4 -9
- mcp_agent/human_input/types.py +2 -3
- mcp_agent/logging/events.py +1 -5
- mcp_agent/logging/json_serializer.py +7 -6
- mcp_agent/logging/listeners.py +20 -23
- mcp_agent/logging/logger.py +15 -17
- mcp_agent/logging/rich_progress.py +10 -8
- mcp_agent/logging/tracing.py +4 -6
- mcp_agent/logging/transport.py +24 -24
- mcp_agent/mcp/gen_client.py +4 -12
- mcp_agent/mcp/interfaces.py +107 -88
- mcp_agent/mcp/mcp_agent_client_session.py +11 -19
- mcp_agent/mcp/mcp_agent_server.py +8 -10
- mcp_agent/mcp/mcp_aggregator.py +49 -122
- mcp_agent/mcp/mcp_connection_manager.py +16 -37
- mcp_agent/mcp/prompt_message_multipart.py +12 -18
- mcp_agent/mcp/prompt_serialization.py +13 -38
- mcp_agent/mcp/prompts/prompt_load.py +99 -0
- mcp_agent/mcp/prompts/prompt_server.py +21 -128
- mcp_agent/mcp/prompts/prompt_template.py +20 -42
- mcp_agent/mcp/resource_utils.py +8 -17
- mcp_agent/mcp/sampling.py +62 -64
- mcp_agent/mcp/stdio.py +11 -8
- mcp_agent/mcp_server/__init__.py +1 -1
- mcp_agent/mcp_server/agent_server.py +10 -17
- mcp_agent/mcp_server_registry.py +13 -35
- mcp_agent/resources/examples/data-analysis/analysis-campaign.py +1 -1
- mcp_agent/resources/examples/data-analysis/analysis.py +1 -1
- mcp_agent/resources/examples/data-analysis/slides.py +110 -0
- mcp_agent/resources/examples/internal/agent.py +2 -1
- mcp_agent/resources/examples/internal/job.py +2 -1
- mcp_agent/resources/examples/internal/prompt_category.py +1 -1
- mcp_agent/resources/examples/internal/prompt_sizing.py +3 -5
- mcp_agent/resources/examples/internal/sizer.py +2 -1
- mcp_agent/resources/examples/internal/social.py +2 -1
- mcp_agent/resources/examples/mcp_researcher/researcher-eval.py +1 -1
- mcp_agent/resources/examples/prompting/__init__.py +1 -1
- mcp_agent/resources/examples/prompting/agent.py +2 -1
- mcp_agent/resources/examples/prompting/image_server.py +5 -11
- mcp_agent/resources/examples/researcher/researcher-eval.py +1 -1
- mcp_agent/resources/examples/researcher/researcher-imp.py +3 -4
- mcp_agent/resources/examples/researcher/researcher.py +2 -1
- mcp_agent/resources/examples/workflows/agent_build.py +2 -1
- mcp_agent/resources/examples/workflows/chaining.py +2 -1
- mcp_agent/resources/examples/workflows/evaluator.py +2 -1
- mcp_agent/resources/examples/workflows/human_input.py +2 -1
- mcp_agent/resources/examples/workflows/orchestrator.py +2 -1
- mcp_agent/resources/examples/workflows/parallel.py +2 -1
- mcp_agent/resources/examples/workflows/router.py +2 -1
- mcp_agent/resources/examples/workflows/sse.py +1 -1
- mcp_agent/telemetry/usage_tracking.py +2 -1
- mcp_agent/ui/console_display.py +17 -41
- mcp_agent/workflows/embedding/embedding_base.py +1 -4
- mcp_agent/workflows/embedding/embedding_cohere.py +2 -2
- mcp_agent/workflows/embedding/embedding_openai.py +4 -13
- mcp_agent/workflows/evaluator_optimizer/evaluator_optimizer.py +23 -57
- mcp_agent/workflows/intent_classifier/intent_classifier_base.py +5 -8
- mcp_agent/workflows/intent_classifier/intent_classifier_embedding.py +7 -11
- mcp_agent/workflows/intent_classifier/intent_classifier_embedding_cohere.py +4 -8
- mcp_agent/workflows/intent_classifier/intent_classifier_embedding_openai.py +4 -8
- mcp_agent/workflows/intent_classifier/intent_classifier_llm.py +11 -22
- mcp_agent/workflows/intent_classifier/intent_classifier_llm_anthropic.py +3 -3
- mcp_agent/workflows/intent_classifier/intent_classifier_llm_openai.py +4 -6
- mcp_agent/workflows/llm/anthropic_utils.py +8 -29
- mcp_agent/workflows/llm/augmented_llm.py +94 -332
- mcp_agent/workflows/llm/augmented_llm_anthropic.py +43 -76
- mcp_agent/workflows/llm/augmented_llm_openai.py +46 -100
- mcp_agent/workflows/llm/augmented_llm_passthrough.py +42 -20
- mcp_agent/workflows/llm/augmented_llm_playback.py +8 -6
- mcp_agent/workflows/llm/memory.py +103 -0
- mcp_agent/workflows/llm/model_factory.py +9 -21
- mcp_agent/workflows/llm/openai_utils.py +1 -1
- mcp_agent/workflows/llm/prompt_utils.py +39 -27
- mcp_agent/workflows/llm/providers/multipart_converter_anthropic.py +246 -184
- mcp_agent/workflows/llm/providers/multipart_converter_openai.py +212 -202
- mcp_agent/workflows/llm/providers/openai_multipart.py +19 -61
- mcp_agent/workflows/llm/providers/sampling_converter_anthropic.py +11 -212
- mcp_agent/workflows/llm/providers/sampling_converter_openai.py +13 -215
- mcp_agent/workflows/llm/sampling_converter.py +117 -0
- mcp_agent/workflows/llm/sampling_format_converter.py +12 -29
- mcp_agent/workflows/orchestrator/orchestrator.py +24 -67
- mcp_agent/workflows/orchestrator/orchestrator_models.py +14 -40
- mcp_agent/workflows/parallel/fan_in.py +17 -47
- mcp_agent/workflows/parallel/fan_out.py +6 -12
- mcp_agent/workflows/parallel/parallel_llm.py +9 -26
- mcp_agent/workflows/router/router_base.py +29 -59
- mcp_agent/workflows/router/router_embedding.py +11 -25
- mcp_agent/workflows/router/router_embedding_cohere.py +2 -2
- mcp_agent/workflows/router/router_embedding_openai.py +2 -2
- mcp_agent/workflows/router/router_llm.py +12 -28
- mcp_agent/workflows/swarm/swarm.py +20 -48
- mcp_agent/workflows/swarm/swarm_anthropic.py +2 -2
- mcp_agent/workflows/swarm/swarm_openai.py +2 -2
- fast_agent_mcp-0.1.11.dist-info/RECORD +0 -160
- mcp_agent/workflows/llm/llm_selector.py +0 -345
- {fast_agent_mcp-0.1.11.dist-info → fast_agent_mcp-0.1.13.dist-info}/WHEEL +0 -0
- {fast_agent_mcp-0.1.11.dist-info → fast_agent_mcp-0.1.13.dist-info}/entry_points.txt +0 -0
- {fast_agent_mcp-0.1.11.dist-info → fast_agent_mcp-0.1.13.dist-info}/licenses/LICENSE +0 -0
mcp_agent/core/agent_app.py
CHANGED
@@ -2,25 +2,25 @@
|
|
2
2
|
Main application wrapper for interacting with agents.
|
3
3
|
"""
|
4
4
|
|
5
|
-
from typing import
|
5
|
+
from typing import TYPE_CHECKING, Dict, Optional, Union
|
6
6
|
|
7
7
|
from mcp_agent.app import MCPApp
|
8
|
-
from mcp_agent.mcp.prompt_message_multipart import PromptMessageMultipart
|
9
|
-
from mcp_agent.progress_display import progress_display
|
10
|
-
from mcp_agent.workflows.orchestrator.orchestrator import Orchestrator
|
11
|
-
from mcp_agent.workflows.parallel.parallel_llm import ParallelLLM
|
12
|
-
from mcp_agent.workflows.evaluator_optimizer.evaluator_optimizer import (
|
13
|
-
EvaluatorOptimizerLLM,
|
14
|
-
)
|
15
8
|
|
16
9
|
# Import proxies directly - they handle their own circular imports
|
17
10
|
from mcp_agent.core.proxies import (
|
18
11
|
BaseAgentProxy,
|
12
|
+
ChainProxy,
|
19
13
|
LLMAgentProxy,
|
20
14
|
RouterProxy,
|
21
|
-
ChainProxy,
|
22
15
|
WorkflowProxy,
|
23
16
|
)
|
17
|
+
from mcp_agent.mcp.prompt_message_multipart import PromptMessageMultipart
|
18
|
+
from mcp_agent.progress_display import progress_display
|
19
|
+
from mcp_agent.workflows.evaluator_optimizer.evaluator_optimizer import (
|
20
|
+
EvaluatorOptimizerLLM,
|
21
|
+
)
|
22
|
+
from mcp_agent.workflows.orchestrator.orchestrator import Orchestrator
|
23
|
+
from mcp_agent.workflows.parallel.parallel_llm import ParallelLLM
|
24
24
|
|
25
25
|
# Handle possible circular imports with types
|
26
26
|
if TYPE_CHECKING:
|
@@ -32,15 +32,13 @@ else:
|
|
32
32
|
class AgentApp:
|
33
33
|
"""Main application wrapper"""
|
34
34
|
|
35
|
-
def __init__(self, app: MCPApp, agents: ProxyDict):
|
35
|
+
def __init__(self, app: MCPApp, agents: ProxyDict) -> None:
|
36
36
|
self._app = app
|
37
37
|
self._agents = agents
|
38
38
|
# Optional: set default agent for direct calls
|
39
39
|
self._default = next(iter(agents)) if agents else None
|
40
40
|
|
41
|
-
async def send_prompt(
|
42
|
-
self, prompt: PromptMessageMultipart, agent_name: Optional[str] = None
|
43
|
-
) -> str:
|
41
|
+
async def send_prompt(self, prompt: PromptMessageMultipart, agent_name: Optional[str] = None) -> str:
|
44
42
|
"""
|
45
43
|
Send a PromptMessageMultipart to an agent
|
46
44
|
|
@@ -112,7 +110,7 @@ class AgentApp:
|
|
112
110
|
|
113
111
|
proxy = self._agents[target]
|
114
112
|
return await proxy.apply_prompt(prompt_name, arguments)
|
115
|
-
|
113
|
+
|
116
114
|
async def with_resource(
|
117
115
|
self,
|
118
116
|
prompt_content: Union[str, PromptMessageMultipart],
|
@@ -218,15 +216,9 @@ class AgentApp:
|
|
218
216
|
found_prompts = False
|
219
217
|
for agent_name, agent_proxy in self._agents.items():
|
220
218
|
# Check if agent has an mcp_aggregator (agent instance)
|
221
|
-
if hasattr(agent_proxy, "_agent") and hasattr(
|
222
|
-
|
223
|
-
|
224
|
-
rich_print(
|
225
|
-
f"\n[bold]Fetching prompts for agent [cyan]{agent_name}[/cyan]...[/bold]"
|
226
|
-
)
|
227
|
-
prompt_servers = (
|
228
|
-
await agent_proxy._agent.list_prompts()
|
229
|
-
)
|
219
|
+
if hasattr(agent_proxy, "_agent") and hasattr(agent_proxy._agent, "list_prompts"):
|
220
|
+
rich_print(f"\n[bold]Fetching prompts for agent [cyan]{agent_name}[/cyan]...[/bold]")
|
221
|
+
prompt_servers = await agent_proxy._agent.list_prompts()
|
230
222
|
|
231
223
|
if prompt_servers:
|
232
224
|
found_prompts = True
|
@@ -234,31 +226,15 @@ class AgentApp:
|
|
234
226
|
server_name,
|
235
227
|
prompts_info,
|
236
228
|
) in prompt_servers.items():
|
237
|
-
if (
|
238
|
-
|
239
|
-
and hasattr(prompts_info, "prompts")
|
240
|
-
and prompts_info.prompts
|
241
|
-
):
|
242
|
-
rich_print(
|
243
|
-
f"\n[bold cyan]{server_name}:[/bold cyan]"
|
244
|
-
)
|
229
|
+
if prompts_info and hasattr(prompts_info, "prompts") and prompts_info.prompts:
|
230
|
+
rich_print(f"\n[bold cyan]{server_name}:[/bold cyan]")
|
245
231
|
for prompt in prompts_info.prompts:
|
246
232
|
rich_print(f" {prompt.name}")
|
247
|
-
elif (
|
248
|
-
|
249
|
-
and prompts_info
|
250
|
-
):
|
251
|
-
rich_print(
|
252
|
-
f"\n[bold cyan]{server_name}:[/bold cyan]"
|
253
|
-
)
|
233
|
+
elif isinstance(prompts_info, list) and prompts_info:
|
234
|
+
rich_print(f"\n[bold cyan]{server_name}:[/bold cyan]")
|
254
235
|
for prompt in prompts_info:
|
255
|
-
if (
|
256
|
-
|
257
|
-
and "name" in prompt
|
258
|
-
):
|
259
|
-
rich_print(
|
260
|
-
f" {prompt['name']}"
|
261
|
-
)
|
236
|
+
if isinstance(prompt, dict) and "name" in prompt:
|
237
|
+
rich_print(f" {prompt['name']}")
|
262
238
|
else:
|
263
239
|
rich_print(f" {prompt}")
|
264
240
|
|
@@ -269,8 +245,8 @@ class AgentApp:
|
|
269
245
|
continue
|
270
246
|
elif "select_prompt" in command_result:
|
271
247
|
from rich import print as rich_print
|
272
|
-
from rich.table import Table
|
273
248
|
from rich.console import Console
|
249
|
+
from rich.table import Table
|
274
250
|
|
275
251
|
console = Console()
|
276
252
|
|
@@ -278,12 +254,8 @@ class AgentApp:
|
|
278
254
|
current_proxy = self._agents[agent]
|
279
255
|
|
280
256
|
# Check if the agent has prompt capabilities
|
281
|
-
if not hasattr(current_proxy, "_agent") or not hasattr(
|
282
|
-
|
283
|
-
):
|
284
|
-
rich_print(
|
285
|
-
f"[red]Current agent '{agent}' does not support prompts[/red]"
|
286
|
-
)
|
257
|
+
if not hasattr(current_proxy, "_agent") or not hasattr(current_proxy._agent, "list_prompts"):
|
258
|
+
rich_print(f"[red]Current agent '{agent}' does not support prompts[/red]")
|
287
259
|
continue
|
288
260
|
|
289
261
|
try:
|
@@ -291,15 +263,11 @@ class AgentApp:
|
|
291
263
|
all_prompts = []
|
292
264
|
|
293
265
|
# Get prompts from the current agent
|
294
|
-
rich_print(
|
295
|
-
f"\n[bold]Fetching prompts for agent [cyan]{agent}[/cyan]...[/bold]"
|
296
|
-
)
|
266
|
+
rich_print(f"\n[bold]Fetching prompts for agent [cyan]{agent}[/cyan]...[/bold]")
|
297
267
|
prompt_servers = await current_proxy._agent.list_prompts()
|
298
268
|
|
299
269
|
if not prompt_servers:
|
300
|
-
rich_print(
|
301
|
-
"[yellow]No prompts available for this agent[/yellow]"
|
302
|
-
)
|
270
|
+
rich_print("[yellow]No prompts available for this agent[/yellow]")
|
303
271
|
continue
|
304
272
|
|
305
273
|
# Process retrieved prompts
|
@@ -319,9 +287,7 @@ class AgentApp:
|
|
319
287
|
for prompt in prompts:
|
320
288
|
# Basic prompt information
|
321
289
|
prompt_name = getattr(prompt, "name", "Unknown")
|
322
|
-
description = getattr(
|
323
|
-
prompt, "description", "No description"
|
324
|
-
)
|
290
|
+
description = getattr(prompt, "description", "No description")
|
325
291
|
|
326
292
|
# Extract argument information
|
327
293
|
arg_names = []
|
@@ -339,9 +305,7 @@ class AgentApp:
|
|
339
305
|
arg_names.append(name)
|
340
306
|
|
341
307
|
# Store description if available
|
342
|
-
description = getattr(
|
343
|
-
arg, "description", None
|
344
|
-
)
|
308
|
+
description = getattr(arg, "description", None)
|
345
309
|
if description:
|
346
310
|
arg_descriptions[name] = description
|
347
311
|
|
@@ -371,32 +335,20 @@ class AgentApp:
|
|
371
335
|
|
372
336
|
# If no prompts were found
|
373
337
|
if not all_prompts:
|
374
|
-
rich_print(
|
375
|
-
"[yellow]No prompts available for this agent[/yellow]"
|
376
|
-
)
|
338
|
+
rich_print("[yellow]No prompts available for this agent[/yellow]")
|
377
339
|
continue
|
378
340
|
|
379
341
|
# Sort prompts by server then name
|
380
342
|
all_prompts.sort(key=lambda p: (p["server"], p["name"]))
|
381
343
|
|
382
344
|
# Check if a specific prompt was requested
|
383
|
-
if
|
384
|
-
"prompt_name" in command_result
|
385
|
-
and command_result["prompt_name"]
|
386
|
-
):
|
345
|
+
if "prompt_name" in command_result and command_result["prompt_name"]:
|
387
346
|
requested_name = command_result["prompt_name"]
|
388
347
|
# Find the prompt in our list (either by name or namespaced name)
|
389
|
-
matching_prompts = [
|
390
|
-
p
|
391
|
-
for p in all_prompts
|
392
|
-
if p["name"] == requested_name
|
393
|
-
or p["namespaced_name"] == requested_name
|
394
|
-
]
|
348
|
+
matching_prompts = [p for p in all_prompts if p["name"] == requested_name or p["namespaced_name"] == requested_name]
|
395
349
|
|
396
350
|
if not matching_prompts:
|
397
|
-
rich_print(
|
398
|
-
f"[red]Prompt '{requested_name}' not found[/red]"
|
399
|
-
)
|
351
|
+
rich_print(f"[red]Prompt '{requested_name}' not found[/red]")
|
400
352
|
rich_print("[yellow]Available prompts:[/yellow]")
|
401
353
|
for p in all_prompts:
|
402
354
|
rich_print(f" {p['namespaced_name']}")
|
@@ -407,22 +359,16 @@ class AgentApp:
|
|
407
359
|
selected_prompt = matching_prompts[0]
|
408
360
|
else:
|
409
361
|
# If multiple matches, show them and ask user to be more specific
|
410
|
-
rich_print(
|
411
|
-
f"[yellow]Multiple prompts match '{requested_name}':[/yellow]"
|
412
|
-
)
|
362
|
+
rich_print(f"[yellow]Multiple prompts match '{requested_name}':[/yellow]")
|
413
363
|
for i, p in enumerate(matching_prompts):
|
414
|
-
rich_print(
|
415
|
-
f" {i + 1}. {p['namespaced_name']} - {p['description']}"
|
416
|
-
)
|
364
|
+
rich_print(f" {i + 1}. {p['namespaced_name']} - {p['description']}")
|
417
365
|
|
418
366
|
# Ask user to select one
|
419
367
|
from mcp_agent.core.enhanced_prompt import (
|
420
368
|
get_selection_input,
|
421
369
|
)
|
422
370
|
|
423
|
-
selection = await get_selection_input(
|
424
|
-
"Enter prompt number to select: ", default="1"
|
425
|
-
)
|
371
|
+
selection = await get_selection_input("Enter prompt number to select: ", default="1")
|
426
372
|
|
427
373
|
try:
|
428
374
|
idx = int(selection) - 1
|
@@ -432,9 +378,7 @@ class AgentApp:
|
|
432
378
|
rich_print("[red]Invalid selection[/red]")
|
433
379
|
continue
|
434
380
|
except ValueError:
|
435
|
-
rich_print(
|
436
|
-
"[red]Invalid input, please enter a number[/red]"
|
437
|
-
)
|
381
|
+
rich_print("[red]Invalid input, please enter a number[/red]")
|
438
382
|
continue
|
439
383
|
else:
|
440
384
|
# Display prompt selection UI
|
@@ -455,9 +399,7 @@ class AgentApp:
|
|
455
399
|
if required_args and optional_args:
|
456
400
|
args_display = f"[bold]{len(required_args)}[/bold]+{len(optional_args)}"
|
457
401
|
elif required_args:
|
458
|
-
args_display = (
|
459
|
-
f"[bold]{len(required_args)}[/bold]"
|
460
|
-
)
|
402
|
+
args_display = f"[bold]{len(required_args)}[/bold]"
|
461
403
|
elif optional_args:
|
462
404
|
args_display = f"{len(optional_args)} opt"
|
463
405
|
else:
|
@@ -472,9 +414,7 @@ class AgentApp:
|
|
472
414
|
)
|
473
415
|
|
474
416
|
console.print(table)
|
475
|
-
prompt_names = [
|
476
|
-
str(i + 1) for i in range(len(all_prompts))
|
477
|
-
]
|
417
|
+
prompt_names = [str(i + 1) for i in range(len(all_prompts))]
|
478
418
|
|
479
419
|
# Ask user to select a prompt
|
480
420
|
from mcp_agent.core.enhanced_prompt import (
|
@@ -489,9 +429,7 @@ class AgentApp:
|
|
489
429
|
|
490
430
|
# Make cancellation easier
|
491
431
|
if not selection or selection.strip() == "":
|
492
|
-
rich_print(
|
493
|
-
"[yellow]Prompt selection cancelled[/yellow]"
|
494
|
-
)
|
432
|
+
rich_print("[yellow]Prompt selection cancelled[/yellow]")
|
495
433
|
continue
|
496
434
|
|
497
435
|
try:
|
@@ -502,17 +440,13 @@ class AgentApp:
|
|
502
440
|
rich_print("[red]Invalid selection[/red]")
|
503
441
|
continue
|
504
442
|
except ValueError:
|
505
|
-
rich_print(
|
506
|
-
"[red]Invalid input, please enter a number[/red]"
|
507
|
-
)
|
443
|
+
rich_print("[red]Invalid input, please enter a number[/red]")
|
508
444
|
continue
|
509
445
|
|
510
446
|
# Get our prompt arguments
|
511
447
|
required_args = selected_prompt["required_args"]
|
512
448
|
optional_args = selected_prompt["optional_args"]
|
513
|
-
arg_descriptions = selected_prompt.get(
|
514
|
-
"arg_descriptions", {}
|
515
|
-
)
|
449
|
+
arg_descriptions = selected_prompt.get("arg_descriptions", {})
|
516
450
|
|
517
451
|
# Always initialize arg_values
|
518
452
|
arg_values = {}
|
@@ -525,13 +459,9 @@ class AgentApp:
|
|
525
459
|
f"\n[bold]Prompt [cyan]{selected_prompt['name']}[/cyan] requires {len(required_args)} arguments and has {len(optional_args)} optional arguments:[/bold]"
|
526
460
|
)
|
527
461
|
elif required_args:
|
528
|
-
rich_print(
|
529
|
-
f"\n[bold]Prompt [cyan]{selected_prompt['name']}[/cyan] requires {len(required_args)} arguments:[/bold]"
|
530
|
-
)
|
462
|
+
rich_print(f"\n[bold]Prompt [cyan]{selected_prompt['name']}[/cyan] requires {len(required_args)} arguments:[/bold]")
|
531
463
|
elif optional_args:
|
532
|
-
rich_print(
|
533
|
-
f"\n[bold]Prompt [cyan]{selected_prompt['name']}[/cyan] has {len(optional_args)} optional arguments:[/bold]"
|
534
|
-
)
|
464
|
+
rich_print(f"\n[bold]Prompt [cyan]{selected_prompt['name']}[/cyan] has {len(optional_args)} optional arguments:[/bold]")
|
535
465
|
|
536
466
|
# Collect required arguments
|
537
467
|
for arg_name in required_args:
|
@@ -573,21 +503,15 @@ class AgentApp:
|
|
573
503
|
arg_values[arg_name] = arg_value
|
574
504
|
|
575
505
|
# Apply the prompt with or without arguments
|
576
|
-
rich_print(
|
577
|
-
f"\n[bold]Applying prompt [cyan]{selected_prompt['namespaced_name']}[/cyan]...[/bold]"
|
578
|
-
)
|
506
|
+
rich_print(f"\n[bold]Applying prompt [cyan]{selected_prompt['namespaced_name']}[/cyan]...[/bold]")
|
579
507
|
|
580
508
|
# Call apply_prompt on the agent - always pass arg_values (empty dict if no args)
|
581
|
-
await current_proxy._agent.apply_prompt(
|
582
|
-
selected_prompt["namespaced_name"], arg_values
|
583
|
-
)
|
509
|
+
await current_proxy._agent.apply_prompt(selected_prompt["namespaced_name"], arg_values)
|
584
510
|
|
585
511
|
except Exception as e:
|
586
512
|
import traceback
|
587
513
|
|
588
|
-
rich_print(
|
589
|
-
f"[red]Error selecting or applying prompt: {e}[/red]"
|
590
|
-
)
|
514
|
+
rich_print(f"[red]Error selecting or applying prompt: {e}[/red]")
|
591
515
|
rich_print(f"[dim]{traceback.format_exc()}[/dim]")
|
592
516
|
continue
|
593
517
|
|
mcp_agent/core/agent_types.py
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
"""
|
2
|
-
|
2
|
+
Type definitions for agents and agent configurations.
|
3
3
|
"""
|
4
4
|
|
5
|
+
from dataclasses import dataclass
|
5
6
|
from enum import Enum
|
7
|
+
from typing import Callable, Dict, List, Optional, Union
|
8
|
+
|
9
|
+
# Forward imports to avoid circular dependencies
|
10
|
+
from mcp_agent.core.request_params import RequestParams
|
6
11
|
|
7
12
|
|
8
13
|
class AgentType(Enum):
|
@@ -13,4 +18,26 @@ class AgentType(Enum):
|
|
13
18
|
PARALLEL = "parallel"
|
14
19
|
EVALUATOR_OPTIMIZER = "evaluator_optimizer"
|
15
20
|
ROUTER = "router"
|
16
|
-
CHAIN = "chain"
|
21
|
+
CHAIN = "chain"
|
22
|
+
|
23
|
+
|
24
|
+
@dataclass
|
25
|
+
class AgentConfig:
|
26
|
+
"""Configuration for an Agent instance"""
|
27
|
+
|
28
|
+
name: str
|
29
|
+
instruction: Union[str, Callable[[Dict], str]]
|
30
|
+
servers: List[str]
|
31
|
+
model: Optional[str] = None
|
32
|
+
use_history: bool = True
|
33
|
+
default_request_params: Optional[RequestParams] = None
|
34
|
+
human_input: bool = False
|
35
|
+
|
36
|
+
def __post_init__(self):
|
37
|
+
"""Ensure default_request_params exists with proper history setting"""
|
38
|
+
|
39
|
+
if self.default_request_params is None:
|
40
|
+
self.default_request_params = RequestParams(use_history=self.use_history)
|
41
|
+
else:
|
42
|
+
# Override the request params history setting if explicitly configured
|
43
|
+
self.default_request_params.use_history = self.use_history
|
mcp_agent/core/agent_utils.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
Utility functions for agent operations.
|
3
3
|
"""
|
4
4
|
|
5
|
-
from typing import
|
5
|
+
from typing import TYPE_CHECKING, List
|
6
6
|
|
7
7
|
from mcp_agent.event_progress import ProgressAction
|
8
8
|
|
@@ -28,7 +28,7 @@ def unwrap_proxy(proxy: BaseAgentProxy) -> AgentOrWorkflow:
|
|
28
28
|
Returns:
|
29
29
|
The underlying Agent or workflow instance
|
30
30
|
"""
|
31
|
-
from mcp_agent.core.proxies import
|
31
|
+
from mcp_agent.core.proxies import ChainProxy, LLMAgentProxy
|
32
32
|
|
33
33
|
if isinstance(proxy, LLMAgentProxy):
|
34
34
|
return proxy._agent
|
@@ -38,9 +38,7 @@ def unwrap_proxy(proxy: BaseAgentProxy) -> AgentOrWorkflow:
|
|
38
38
|
return proxy._workflow
|
39
39
|
|
40
40
|
|
41
|
-
def get_agent_instances(
|
42
|
-
agent_names: List[str], active_agents: ProxyDict
|
43
|
-
) -> List[AgentOrWorkflow]:
|
41
|
+
def get_agent_instances(agent_names: List[str], active_agents: ProxyDict) -> List[AgentOrWorkflow]:
|
44
42
|
"""
|
45
43
|
Get list of actual agent/workflow instances from a list of names.
|
46
44
|
|
mcp_agent/core/decorators.py
CHANGED
@@ -3,10 +3,10 @@ Decorators for FastAgent applications.
|
|
3
3
|
Contains decorator definitions extracted from fastagent.py.
|
4
4
|
"""
|
5
5
|
|
6
|
-
from typing import Callable, Dict, List, Optional, TypeVar
|
7
|
-
|
6
|
+
from typing import Callable, Dict, List, Literal, Optional, TypeVar
|
7
|
+
|
8
|
+
from mcp_agent.core.agent_types import AgentConfig, AgentType
|
8
9
|
from mcp_agent.workflows.llm.augmented_llm import RequestParams
|
9
|
-
from mcp_agent.core.agent_types import AgentType
|
10
10
|
|
11
11
|
T = TypeVar("T") # For the wrapper classes
|
12
12
|
|
@@ -47,11 +47,7 @@ def _create_decorator(
|
|
47
47
|
# Create base request params
|
48
48
|
def decorator(func: Callable) -> Callable:
|
49
49
|
# Create base request params
|
50
|
-
if
|
51
|
-
request_params is not None
|
52
|
-
or model is not None
|
53
|
-
or use_history != default_use_history
|
54
|
-
):
|
50
|
+
if request_params is not None or model is not None or use_history != default_use_history:
|
55
51
|
max_tokens = 4096 if agent_type == AgentType.BASIC else None
|
56
52
|
params_dict = {"use_history": use_history, "model": model}
|
57
53
|
if max_tokens:
|
@@ -143,9 +139,7 @@ def agent(
|
|
143
139
|
@fast.agent("agent_name", instruction="Your instruction here") # Using keyword arg
|
144
140
|
"""
|
145
141
|
# Use positional argument if provided, otherwise use keyword argument
|
146
|
-
final_instruction =
|
147
|
-
instruction_or_kwarg if instruction_or_kwarg is not None else instruction
|
148
|
-
)
|
142
|
+
final_instruction = instruction_or_kwarg if instruction_or_kwarg is not None else instruction
|
149
143
|
|
150
144
|
decorator = self._create_decorator(
|
151
145
|
AgentType.BASIC,
|
@@ -428,9 +422,7 @@ def chain(
|
|
428
422
|
return decorator
|
429
423
|
|
430
424
|
|
431
|
-
def passthrough(
|
432
|
-
self, name: str = "Passthrough", use_history: bool = True, **kwargs
|
433
|
-
) -> Callable:
|
425
|
+
def passthrough(self, name: str = "Passthrough", use_history: bool = True, **kwargs) -> Callable:
|
434
426
|
"""
|
435
427
|
Decorator to create and register a passthrough agent.
|
436
428
|
A passthrough agent simply returns any input message without modification.
|