fast-agent-mcp 0.1.12__py3-none-any.whl → 0.2.0__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.
Files changed (169) hide show
  1. {fast_agent_mcp-0.1.12.dist-info → fast_agent_mcp-0.2.0.dist-info}/METADATA +3 -4
  2. fast_agent_mcp-0.2.0.dist-info/RECORD +123 -0
  3. mcp_agent/__init__.py +75 -0
  4. mcp_agent/agents/agent.py +61 -415
  5. mcp_agent/agents/base_agent.py +522 -0
  6. mcp_agent/agents/workflow/__init__.py +1 -0
  7. mcp_agent/agents/workflow/chain_agent.py +173 -0
  8. mcp_agent/agents/workflow/evaluator_optimizer.py +362 -0
  9. mcp_agent/agents/workflow/orchestrator_agent.py +591 -0
  10. mcp_agent/{workflows/orchestrator → agents/workflow}/orchestrator_models.py +11 -21
  11. mcp_agent/agents/workflow/parallel_agent.py +182 -0
  12. mcp_agent/agents/workflow/router_agent.py +307 -0
  13. mcp_agent/app.py +15 -19
  14. mcp_agent/cli/commands/bootstrap.py +19 -38
  15. mcp_agent/cli/commands/config.py +4 -4
  16. mcp_agent/cli/commands/setup.py +7 -14
  17. mcp_agent/cli/main.py +7 -10
  18. mcp_agent/cli/terminal.py +3 -3
  19. mcp_agent/config.py +25 -40
  20. mcp_agent/context.py +12 -21
  21. mcp_agent/context_dependent.py +3 -5
  22. mcp_agent/core/agent_types.py +10 -7
  23. mcp_agent/core/direct_agent_app.py +179 -0
  24. mcp_agent/core/direct_decorators.py +443 -0
  25. mcp_agent/core/direct_factory.py +476 -0
  26. mcp_agent/core/enhanced_prompt.py +23 -55
  27. mcp_agent/core/exceptions.py +8 -8
  28. mcp_agent/core/fastagent.py +145 -371
  29. mcp_agent/core/interactive_prompt.py +424 -0
  30. mcp_agent/core/mcp_content.py +17 -17
  31. mcp_agent/core/prompt.py +6 -9
  32. mcp_agent/core/request_params.py +6 -3
  33. mcp_agent/core/validation.py +92 -18
  34. mcp_agent/executor/decorator_registry.py +9 -17
  35. mcp_agent/executor/executor.py +8 -17
  36. mcp_agent/executor/task_registry.py +2 -4
  37. mcp_agent/executor/temporal.py +19 -41
  38. mcp_agent/executor/workflow.py +3 -5
  39. mcp_agent/executor/workflow_signal.py +15 -21
  40. mcp_agent/human_input/handler.py +4 -7
  41. mcp_agent/human_input/types.py +2 -3
  42. mcp_agent/llm/__init__.py +2 -0
  43. mcp_agent/llm/augmented_llm.py +450 -0
  44. mcp_agent/llm/augmented_llm_passthrough.py +162 -0
  45. mcp_agent/llm/augmented_llm_playback.py +83 -0
  46. mcp_agent/llm/memory.py +103 -0
  47. mcp_agent/{workflows/llm → llm}/model_factory.py +22 -16
  48. mcp_agent/{workflows/llm → llm}/prompt_utils.py +1 -3
  49. mcp_agent/llm/providers/__init__.py +8 -0
  50. mcp_agent/{workflows/llm → llm/providers}/anthropic_utils.py +8 -25
  51. mcp_agent/{workflows/llm → llm/providers}/augmented_llm_anthropic.py +56 -194
  52. mcp_agent/llm/providers/augmented_llm_deepseek.py +53 -0
  53. mcp_agent/{workflows/llm → llm/providers}/augmented_llm_openai.py +99 -190
  54. mcp_agent/{workflows/llm → llm}/providers/multipart_converter_anthropic.py +72 -71
  55. mcp_agent/{workflows/llm → llm}/providers/multipart_converter_openai.py +65 -71
  56. mcp_agent/{workflows/llm → llm}/providers/openai_multipart.py +16 -44
  57. mcp_agent/{workflows/llm → llm/providers}/openai_utils.py +4 -4
  58. mcp_agent/{workflows/llm → llm}/providers/sampling_converter_anthropic.py +9 -11
  59. mcp_agent/{workflows/llm → llm}/providers/sampling_converter_openai.py +8 -12
  60. mcp_agent/{workflows/llm → llm}/sampling_converter.py +3 -31
  61. mcp_agent/llm/sampling_format_converter.py +37 -0
  62. mcp_agent/logging/events.py +1 -5
  63. mcp_agent/logging/json_serializer.py +7 -6
  64. mcp_agent/logging/listeners.py +20 -23
  65. mcp_agent/logging/logger.py +17 -19
  66. mcp_agent/logging/rich_progress.py +10 -8
  67. mcp_agent/logging/tracing.py +4 -6
  68. mcp_agent/logging/transport.py +22 -22
  69. mcp_agent/mcp/gen_client.py +1 -3
  70. mcp_agent/mcp/interfaces.py +117 -110
  71. mcp_agent/mcp/logger_textio.py +97 -0
  72. mcp_agent/mcp/mcp_agent_client_session.py +7 -7
  73. mcp_agent/mcp/mcp_agent_server.py +8 -8
  74. mcp_agent/mcp/mcp_aggregator.py +102 -143
  75. mcp_agent/mcp/mcp_connection_manager.py +20 -27
  76. mcp_agent/mcp/prompt_message_multipart.py +68 -16
  77. mcp_agent/mcp/prompt_render.py +77 -0
  78. mcp_agent/mcp/prompt_serialization.py +30 -48
  79. mcp_agent/mcp/prompts/prompt_constants.py +18 -0
  80. mcp_agent/mcp/prompts/prompt_helpers.py +327 -0
  81. mcp_agent/mcp/prompts/prompt_load.py +109 -0
  82. mcp_agent/mcp/prompts/prompt_server.py +155 -195
  83. mcp_agent/mcp/prompts/prompt_template.py +35 -66
  84. mcp_agent/mcp/resource_utils.py +7 -14
  85. mcp_agent/mcp/sampling.py +17 -17
  86. mcp_agent/mcp_server/agent_server.py +13 -17
  87. mcp_agent/mcp_server_registry.py +13 -22
  88. mcp_agent/resources/examples/{workflows → in_dev}/agent_build.py +3 -2
  89. mcp_agent/resources/examples/in_dev/slides.py +110 -0
  90. mcp_agent/resources/examples/internal/agent.py +6 -3
  91. mcp_agent/resources/examples/internal/fastagent.config.yaml +8 -2
  92. mcp_agent/resources/examples/internal/job.py +2 -1
  93. mcp_agent/resources/examples/internal/prompt_category.py +1 -1
  94. mcp_agent/resources/examples/internal/prompt_sizing.py +3 -5
  95. mcp_agent/resources/examples/internal/sizer.py +2 -1
  96. mcp_agent/resources/examples/internal/social.py +2 -1
  97. mcp_agent/resources/examples/prompting/agent.py +2 -1
  98. mcp_agent/resources/examples/prompting/image_server.py +4 -8
  99. mcp_agent/resources/examples/prompting/work_with_image.py +19 -0
  100. mcp_agent/ui/console_display.py +16 -20
  101. fast_agent_mcp-0.1.12.dist-info/RECORD +0 -161
  102. mcp_agent/core/agent_app.py +0 -646
  103. mcp_agent/core/agent_utils.py +0 -71
  104. mcp_agent/core/decorators.py +0 -455
  105. mcp_agent/core/factory.py +0 -463
  106. mcp_agent/core/proxies.py +0 -269
  107. mcp_agent/core/types.py +0 -24
  108. mcp_agent/eval/__init__.py +0 -0
  109. mcp_agent/mcp/stdio.py +0 -111
  110. mcp_agent/resources/examples/data-analysis/analysis-campaign.py +0 -188
  111. mcp_agent/resources/examples/data-analysis/analysis.py +0 -65
  112. mcp_agent/resources/examples/data-analysis/fastagent.config.yaml +0 -41
  113. mcp_agent/resources/examples/data-analysis/mount-point/WA_Fn-UseC_-HR-Employee-Attrition.csv +0 -1471
  114. mcp_agent/resources/examples/mcp_researcher/researcher-eval.py +0 -53
  115. mcp_agent/resources/examples/researcher/fastagent.config.yaml +0 -66
  116. mcp_agent/resources/examples/researcher/researcher-eval.py +0 -53
  117. mcp_agent/resources/examples/researcher/researcher-imp.py +0 -190
  118. mcp_agent/resources/examples/researcher/researcher.py +0 -38
  119. mcp_agent/resources/examples/workflows/chaining.py +0 -44
  120. mcp_agent/resources/examples/workflows/evaluator.py +0 -78
  121. mcp_agent/resources/examples/workflows/fastagent.config.yaml +0 -24
  122. mcp_agent/resources/examples/workflows/human_input.py +0 -25
  123. mcp_agent/resources/examples/workflows/orchestrator.py +0 -73
  124. mcp_agent/resources/examples/workflows/parallel.py +0 -78
  125. mcp_agent/resources/examples/workflows/router.py +0 -53
  126. mcp_agent/resources/examples/workflows/sse.py +0 -23
  127. mcp_agent/telemetry/__init__.py +0 -0
  128. mcp_agent/telemetry/usage_tracking.py +0 -18
  129. mcp_agent/workflows/__init__.py +0 -0
  130. mcp_agent/workflows/embedding/__init__.py +0 -0
  131. mcp_agent/workflows/embedding/embedding_base.py +0 -61
  132. mcp_agent/workflows/embedding/embedding_cohere.py +0 -49
  133. mcp_agent/workflows/embedding/embedding_openai.py +0 -46
  134. mcp_agent/workflows/evaluator_optimizer/__init__.py +0 -0
  135. mcp_agent/workflows/evaluator_optimizer/evaluator_optimizer.py +0 -481
  136. mcp_agent/workflows/intent_classifier/__init__.py +0 -0
  137. mcp_agent/workflows/intent_classifier/intent_classifier_base.py +0 -120
  138. mcp_agent/workflows/intent_classifier/intent_classifier_embedding.py +0 -134
  139. mcp_agent/workflows/intent_classifier/intent_classifier_embedding_cohere.py +0 -45
  140. mcp_agent/workflows/intent_classifier/intent_classifier_embedding_openai.py +0 -45
  141. mcp_agent/workflows/intent_classifier/intent_classifier_llm.py +0 -161
  142. mcp_agent/workflows/intent_classifier/intent_classifier_llm_anthropic.py +0 -60
  143. mcp_agent/workflows/intent_classifier/intent_classifier_llm_openai.py +0 -60
  144. mcp_agent/workflows/llm/__init__.py +0 -0
  145. mcp_agent/workflows/llm/augmented_llm.py +0 -753
  146. mcp_agent/workflows/llm/augmented_llm_passthrough.py +0 -241
  147. mcp_agent/workflows/llm/augmented_llm_playback.py +0 -109
  148. mcp_agent/workflows/llm/providers/__init__.py +0 -8
  149. mcp_agent/workflows/llm/sampling_format_converter.py +0 -22
  150. mcp_agent/workflows/orchestrator/__init__.py +0 -0
  151. mcp_agent/workflows/orchestrator/orchestrator.py +0 -578
  152. mcp_agent/workflows/parallel/__init__.py +0 -0
  153. mcp_agent/workflows/parallel/fan_in.py +0 -350
  154. mcp_agent/workflows/parallel/fan_out.py +0 -187
  155. mcp_agent/workflows/parallel/parallel_llm.py +0 -166
  156. mcp_agent/workflows/router/__init__.py +0 -0
  157. mcp_agent/workflows/router/router_base.py +0 -368
  158. mcp_agent/workflows/router/router_embedding.py +0 -240
  159. mcp_agent/workflows/router/router_embedding_cohere.py +0 -59
  160. mcp_agent/workflows/router/router_embedding_openai.py +0 -59
  161. mcp_agent/workflows/router/router_llm.py +0 -320
  162. mcp_agent/workflows/swarm/__init__.py +0 -0
  163. mcp_agent/workflows/swarm/swarm.py +0 -320
  164. mcp_agent/workflows/swarm/swarm_anthropic.py +0 -42
  165. mcp_agent/workflows/swarm/swarm_openai.py +0 -41
  166. {fast_agent_mcp-0.1.12.dist-info → fast_agent_mcp-0.2.0.dist-info}/WHEEL +0 -0
  167. {fast_agent_mcp-0.1.12.dist-info → fast_agent_mcp-0.2.0.dist-info}/entry_points.txt +0 -0
  168. {fast_agent_mcp-0.1.12.dist-info → fast_agent_mcp-0.2.0.dist-info}/licenses/LICENSE +0 -0
  169. /mcp_agent/{workflows/orchestrator → agents/workflow}/orchestrator_prompts.py +0 -0
@@ -1,71 +0,0 @@
1
- """
2
- Utility functions for agent operations.
3
- """
4
-
5
- from typing import List, TYPE_CHECKING
6
-
7
- from mcp_agent.event_progress import ProgressAction
8
-
9
- # Handle circular imports
10
- if TYPE_CHECKING:
11
- from mcp_agent.core.proxies import BaseAgentProxy
12
- from mcp_agent.core.types import AgentOrWorkflow, ProxyDict
13
- else:
14
- from mcp_agent.core.proxies import BaseAgentProxy
15
-
16
- # Define minimal types for runtime
17
- AgentOrWorkflow = object # Simple placeholder
18
- ProxyDict = dict # Simple placeholder
19
-
20
-
21
- def unwrap_proxy(proxy: BaseAgentProxy) -> AgentOrWorkflow:
22
- """
23
- Unwrap a proxy to get the underlying agent or workflow instance.
24
-
25
- Args:
26
- proxy: The proxy object to unwrap
27
-
28
- Returns:
29
- The underlying Agent or workflow instance
30
- """
31
- from mcp_agent.core.proxies import LLMAgentProxy, ChainProxy
32
-
33
- if isinstance(proxy, LLMAgentProxy):
34
- return proxy._agent
35
- elif isinstance(proxy, ChainProxy):
36
- # Return the ChainProxy itself as the workflow
37
- return proxy
38
- return proxy._workflow
39
-
40
-
41
- def get_agent_instances(
42
- agent_names: List[str], active_agents: ProxyDict
43
- ) -> List[AgentOrWorkflow]:
44
- """
45
- Get list of actual agent/workflow instances from a list of names.
46
-
47
- Args:
48
- agent_names: List of agent names to look up
49
- active_agents: Dictionary of active agent proxies
50
-
51
- Returns:
52
- List of unwrapped agent/workflow instances
53
- """
54
- return [unwrap_proxy(active_agents[name]) for name in agent_names]
55
-
56
-
57
- def log_agent_load(app, agent_name: str) -> None:
58
- """
59
- Log agent loading event to application logger.
60
-
61
- Args:
62
- app: The application instance
63
- agent_name: Name of the agent being loaded
64
- """
65
- app._logger.info(
66
- f"Loaded {agent_name}",
67
- data={
68
- "progress_action": ProgressAction.LOADED,
69
- "agent_name": agent_name,
70
- },
71
- )
@@ -1,455 +0,0 @@
1
- """
2
- Decorators for FastAgent applications.
3
- Contains decorator definitions extracted from fastagent.py.
4
- """
5
-
6
- from typing import Callable, Dict, List, Optional, TypeVar, Literal
7
- from mcp_agent.core.agent_types import AgentConfig, AgentType
8
- from mcp_agent.workflows.llm.augmented_llm import RequestParams
9
-
10
- T = TypeVar("T") # For the wrapper classes
11
-
12
-
13
- def _create_decorator(
14
- self,
15
- agent_type: AgentType,
16
- default_name: str = None,
17
- default_instruction: str = None,
18
- default_servers: List[str] = None,
19
- default_use_history: bool = True,
20
- wrapper_needed: bool = False,
21
- **extra_defaults,
22
- ) -> Callable:
23
- """
24
- Factory method for creating agent decorators with common behavior.
25
-
26
- Args:
27
- agent_type: Type of agent/workflow to create
28
- default_name: Default name to use if not provided
29
- default_instruction: Default instruction to use if not provided
30
- default_servers: Default servers list to use if not provided
31
- default_use_history: Default history setting
32
- wrapper_needed: Whether to wrap the decorated function
33
- **extra_defaults: Additional agent/workflow-specific parameters
34
- """
35
-
36
- def decorator_wrapper(**kwargs):
37
- # Apply defaults for common parameters
38
- name = kwargs.get("name", default_name or f"{agent_type.name.title()}")
39
- instruction = kwargs.get("instruction", default_instruction or "")
40
- servers = kwargs.get("servers", default_servers or [])
41
- model = kwargs.get("model", None)
42
- use_history = kwargs.get("use_history", default_use_history)
43
- request_params = kwargs.get("request_params", None)
44
- human_input = kwargs.get("human_input", False)
45
-
46
- # Create base request params
47
- def decorator(func: Callable) -> Callable:
48
- # Create base request params
49
- if (
50
- request_params is not None
51
- or model is not None
52
- or use_history != default_use_history
53
- ):
54
- max_tokens = 4096 if agent_type == AgentType.BASIC else None
55
- params_dict = {"use_history": use_history, "model": model}
56
- if max_tokens:
57
- params_dict["maxTokens"] = max_tokens
58
- if request_params:
59
- params_dict.update(request_params)
60
- base_params = RequestParams(**params_dict)
61
- else:
62
- base_params = RequestParams(use_history=use_history)
63
-
64
- # Create agent configuration
65
- config = AgentConfig(
66
- name=name,
67
- instruction=instruction,
68
- servers=servers,
69
- model=model,
70
- use_history=use_history,
71
- default_request_params=base_params,
72
- human_input=human_input,
73
- )
74
-
75
- # Build agent/workflow specific data
76
- agent_data = {
77
- "config": config,
78
- "type": agent_type.value,
79
- "func": func,
80
- }
81
-
82
- # Add extra parameters specific to this agent type
83
- for key, value in kwargs.items():
84
- if key not in [
85
- "name",
86
- "instruction",
87
- "servers",
88
- "model",
89
- "use_history",
90
- "request_params",
91
- "human_input",
92
- ]:
93
- agent_data[key] = value
94
-
95
- # Store the configuration under the agent name
96
- self.agents[name] = agent_data
97
-
98
- # Either wrap or return the original function
99
- if wrapper_needed:
100
-
101
- async def wrapper(*args, **kwargs):
102
- return await func(*args, **kwargs)
103
-
104
- return wrapper
105
- return func
106
-
107
- return decorator
108
-
109
- return decorator_wrapper
110
-
111
-
112
- def agent(
113
- self,
114
- name: str = "Agent",
115
- instruction_or_kwarg: str = None,
116
- *,
117
- instruction: str = "You are a helpful agent.",
118
- servers: List[str] = [],
119
- model: str | None = None,
120
- use_history: bool = True,
121
- request_params: Optional[Dict] = None,
122
- human_input: bool = False,
123
- ) -> Callable:
124
- """
125
- Decorator to create and register an agent with configuration.
126
-
127
- Args:
128
- name: Name of the agent
129
- instruction_or_kwarg: Optional positional parameter for instruction
130
- instruction: Base instruction for the agent (keyword arg)
131
- servers: List of server names the agent should connect to
132
- model: Model specification string (highest precedence)
133
- use_history: Whether to maintain conversation history
134
- request_params: Additional request parameters for the LLM
135
- human_input: Whether to enable human input capabilities
136
-
137
- The instruction can be provided either as a second positional argument
138
- or as a keyword argument. Positional argument takes precedence when both are provided.
139
-
140
- Usage:
141
- @fast.agent("agent_name", "Your instruction here") # Using positional arg
142
- @fast.agent("agent_name", instruction="Your instruction here") # Using keyword arg
143
- """
144
- # Use positional argument if provided, otherwise use keyword argument
145
- final_instruction = (
146
- instruction_or_kwarg if instruction_or_kwarg is not None else instruction
147
- )
148
-
149
- decorator = self._create_decorator(
150
- AgentType.BASIC,
151
- default_name="Agent",
152
- default_instruction="You are a helpful agent.",
153
- default_use_history=True,
154
- )(
155
- name=name,
156
- instruction=final_instruction,
157
- servers=servers,
158
- model=model,
159
- use_history=use_history,
160
- request_params=request_params,
161
- human_input=human_input,
162
- )
163
- return decorator
164
-
165
-
166
- def orchestrator(
167
- self,
168
- name: str = "Orchestrator",
169
- *,
170
- instruction: str | None = None,
171
- agents: List[str],
172
- model: str | None = None,
173
- use_history: bool = False,
174
- request_params: Optional[Dict] = None,
175
- human_input: bool = False,
176
- plan_type: Literal["full", "iterative"] = "full",
177
- max_iterations: int = 30, # Add the max_iterations parameter with default value
178
- ) -> Callable:
179
- """
180
- Decorator to create and register an orchestrator.
181
-
182
- Args:
183
- name: Name of the orchestrator
184
- instruction: Base instruction for the orchestrator
185
- agents: List of agent names this orchestrator can use
186
- model: Model specification string (highest precedence)
187
- use_history: Whether to maintain conversation history (forced false)
188
- request_params: Additional request parameters for the LLM
189
- human_input: Whether to enable human input capabilities
190
- plan_type: Planning approach - "full" generates entire plan first, "iterative" plans one step at a time
191
- max_iterations: Maximum number of planning iterations (default: 10)
192
- """
193
- default_instruction = """
194
- You are an expert planner. Given an objective task and a list of MCP servers (which are collections of tools)
195
- or Agents (which are collections of servers), your job is to break down the objective into a series of steps,
196
- which can be performed by LLMs with access to the servers or agents.
197
- """
198
-
199
- # Handle request_params update with max_iterations
200
- if request_params is None:
201
- request_params = {"max_iterations": max_iterations}
202
- elif isinstance(request_params, dict):
203
- if "max_iterations" not in request_params:
204
- request_params["max_iterations"] = max_iterations
205
-
206
- decorator = self._create_decorator(
207
- AgentType.ORCHESTRATOR,
208
- default_name="Orchestrator",
209
- default_instruction=default_instruction,
210
- default_servers=[],
211
- default_use_history=False,
212
- )(
213
- name=name,
214
- instruction=instruction,
215
- child_agents=agents,
216
- model=model,
217
- use_history=use_history,
218
- request_params=request_params,
219
- human_input=human_input,
220
- plan_type=plan_type,
221
- )
222
- return decorator
223
-
224
-
225
- def parallel(
226
- self,
227
- name: str,
228
- fan_out: List[str],
229
- fan_in: Optional[str] = None,
230
- instruction: str = "",
231
- model: str | None = None,
232
- use_history: bool = True,
233
- request_params: Optional[Dict] = None,
234
- include_request: bool = True,
235
- ) -> Callable:
236
- """
237
- Decorator to create and register a parallel executing agent.
238
-
239
- Args:
240
- name: Name of the parallel executing agent
241
- fan_out: List of parallel execution agents
242
- fan_in: Optional name of collecting agent. If not provided, a passthrough agent
243
- will be created automatically with the name "{name}_fan_in"
244
- instruction: Optional instruction for the parallel agent
245
- model: Model specification string
246
- use_history: Whether to maintain conversation history
247
- request_params: Additional request parameters for the LLM
248
- include_request: Whether to include the original request in the fan-in message
249
- """
250
- # If fan_in is not provided, create a passthrough agent with a derived name
251
- if fan_in is None:
252
- passthrough_name = f"{name}_fan_in"
253
-
254
- # Register the passthrough agent directly in self.agents
255
- self.agents[passthrough_name] = {
256
- "config": AgentConfig(
257
- name=passthrough_name,
258
- model="passthrough",
259
- instruction=f"This agent combines the results from the fan-out agents verbatim. {name}",
260
- servers=[],
261
- use_history=use_history,
262
- ),
263
- "type": AgentType.BASIC.value, # Using BASIC type since we're just attaching a PassthroughLLM
264
- "func": lambda x: x, # Simple passthrough function (never actually called)
265
- }
266
-
267
- # Use this passthrough as the fan-in
268
- fan_in = passthrough_name
269
-
270
- decorator = self._create_decorator(
271
- AgentType.PARALLEL,
272
- default_instruction="",
273
- default_servers=[],
274
- default_use_history=True,
275
- )(
276
- name=name,
277
- fan_in=fan_in,
278
- fan_out=fan_out,
279
- instruction=instruction,
280
- model=model,
281
- use_history=use_history,
282
- request_params=request_params,
283
- include_request=include_request,
284
- )
285
- return decorator
286
-
287
-
288
- def evaluator_optimizer(
289
- self,
290
- name: str,
291
- generator: str,
292
- evaluator: str,
293
- min_rating: str = "GOOD",
294
- max_refinements: int = 3,
295
- use_history: bool = True,
296
- request_params: Optional[Dict] = None,
297
- instruction: Optional[str] = None,
298
- ) -> Callable:
299
- """
300
- Decorator to create and register an evaluator-optimizer workflow.
301
-
302
- Args:
303
- name: Name of the workflow
304
- generator: Name of the generator agent
305
- evaluator: Name of the evaluator agent
306
- min_rating: Minimum acceptable quality rating (EXCELLENT, GOOD, FAIR, POOR)
307
- max_refinements: Maximum number of refinement iterations
308
- use_history: Whether to maintain conversation history
309
- request_params: Additional request parameters for the LLM
310
- instruction: Optional instruction for the workflow (if not provided, uses generator's instruction)
311
- """
312
- decorator = self._create_decorator(
313
- AgentType.EVALUATOR_OPTIMIZER,
314
- default_instruction="", # We'll get instruction from generator or override
315
- default_servers=[],
316
- default_use_history=True,
317
- wrapper_needed=True,
318
- )(
319
- name=name,
320
- generator=generator,
321
- evaluator=evaluator,
322
- min_rating=min_rating,
323
- max_refinements=max_refinements,
324
- use_history=use_history,
325
- request_params=request_params,
326
- instruction=instruction, # Pass through any custom instruction
327
- )
328
- return decorator
329
-
330
-
331
- def router(
332
- self,
333
- name: str,
334
- agents: List[str],
335
- # servers: List[str] = [],
336
- model: Optional[str] = None,
337
- use_history: bool = True,
338
- request_params: Optional[Dict] = None,
339
- human_input: bool = False,
340
- ) -> Callable:
341
- """
342
- Decorator to create and register a router.
343
-
344
- Args:
345
- name: Name of the router
346
- agents: List of agent names this router can delegate to
347
- servers: List of server names the router can use directly (currently not supported)
348
- model: Model specification string
349
- use_history: Whether to maintain conversation history
350
- request_params: Additional request parameters for the LLM
351
- human_input: Whether to enable human input capabilities
352
- """
353
- decorator = self._create_decorator(
354
- AgentType.ROUTER,
355
- default_instruction="",
356
- default_servers=[],
357
- default_use_history=False,
358
- wrapper_needed=True,
359
- )(
360
- name=name,
361
- agents=agents,
362
- model=model,
363
- use_history=use_history,
364
- request_params=request_params,
365
- human_input=human_input,
366
- )
367
- return decorator
368
-
369
-
370
- def chain(
371
- self,
372
- name: str = "Chain",
373
- *,
374
- sequence: List[str] = None,
375
- agents: List[str] = None, # Alias for sequence
376
- instruction: str = None,
377
- model: str | None = None,
378
- use_history: bool = True,
379
- request_params: Optional[Dict] = None,
380
- continue_with_final: bool = True,
381
- cumulative: bool = False,
382
- ) -> Callable:
383
- """
384
- Decorator to create and register a chain of agents.
385
-
386
- Args:
387
- name: Name of the chain
388
- sequence: List of agent names in order of execution (preferred name)
389
- agents: Alias for sequence (backwards compatibility)
390
- instruction: Optional custom instruction for the chain (if none provided, will autogenerate based on sequence)
391
- model: Model specification string (not used directly in chain)
392
- use_history: Whether to maintain conversation history
393
- request_params: Additional request parameters
394
- continue_with_final: When using prompt(), whether to continue with the final agent after processing chain (default: True)
395
- cumulative: When True, each agent receives all previous agent responses concatenated (default: False)
396
- When False, each agent only gets the output of the previous agent (default behavior)
397
- """
398
- # Support both parameter names
399
- agent_sequence = sequence or agents
400
- if agent_sequence is None:
401
- raise ValueError("Either 'sequence' or 'agents' parameter must be provided")
402
-
403
- # Auto-generate instruction if not provided
404
- if instruction is None:
405
- # Generate an appropriate instruction based on mode
406
- if cumulative:
407
- instruction = f"Cumulative chain of agents: {', '.join(agent_sequence)}"
408
- else:
409
- instruction = f"Chain of agents: {', '.join(agent_sequence)}"
410
-
411
- decorator = self._create_decorator(
412
- AgentType.CHAIN,
413
- default_name="Chain",
414
- default_instruction=instruction,
415
- default_use_history=True,
416
- wrapper_needed=True,
417
- )(
418
- name=name,
419
- sequence=agent_sequence,
420
- instruction=instruction,
421
- model=model,
422
- use_history=use_history,
423
- request_params=request_params,
424
- continue_with_final=continue_with_final,
425
- cumulative=cumulative,
426
- )
427
- return decorator
428
-
429
-
430
- def passthrough(
431
- self, name: str = "Passthrough", use_history: bool = True, **kwargs
432
- ) -> Callable:
433
- """
434
- Decorator to create and register a passthrough agent.
435
- A passthrough agent simply returns any input message without modification.
436
-
437
- This is useful for parallel workflows where no fan-in aggregation is needed
438
- (the fan-in agent can be a passthrough that simply returns the combined outputs).
439
-
440
- Args:
441
- name: Name of the passthrough agent
442
- use_history: Whether to maintain conversation history
443
- **kwargs: Additional parameters (ignored, for compatibility)
444
- """
445
- decorator = self._create_decorator(
446
- AgentType.BASIC, # Using BASIC agent type since we'll use a regular agent with PassthroughLLM
447
- default_name="Passthrough",
448
- default_instruction="Passthrough agent that returns input without modification",
449
- default_use_history=use_history,
450
- wrapper_needed=True,
451
- )(
452
- name=name,
453
- use_history=use_history,
454
- )
455
- return decorator