forked from lastmile-ai/mcp-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.py
More file actions
70 lines (54 loc) · 1.98 KB
/
basic.py
File metadata and controls
70 lines (54 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
Example of using Temporal as the execution engine for MCP Agent workflows.
This example demonstrates how to create a workflow using the app.workflow and app.workflow_run
decorators, and how to run it using the Temporal executor.
"""
import asyncio
import logging
import os
from mcp_agent.agents.agent import Agent
from mcp_agent.executor.temporal import TemporalExecutor
from mcp_agent.executor.workflow import Workflow, WorkflowResult
from mcp_agent.workflows.llm.augmented_llm_openai import OpenAIAugmentedLLM
from main import app
# Initialize logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
@app.workflow
class SimpleWorkflow(Workflow[str]):
"""
A simple workflow that demonstrates the basic structure of a Temporal workflow.
"""
@app.workflow_run
async def run(self, input: str) -> WorkflowResult[str]:
"""
Run the workflow, processing the input data.
Args:
input_data: The data to process
Returns:
A WorkflowResult containing the processed data
"""
finder_agent = Agent(
name="finder",
instruction="""You are a helpful assistant.""",
server_names=["fetch", "filesystem"],
)
context = app.context
context.config.mcp.servers["filesystem"].args.extend([os.getcwd()])
async with finder_agent:
finder_llm = await finder_agent.attach_llm(OpenAIAugmentedLLM)
result = await finder_llm.generate_str(
message=input,
)
return WorkflowResult(value=result)
async def main():
async with app.run() as agent_app:
executor: TemporalExecutor = agent_app.executor
handle = await executor.start_workflow(
"SimpleWorkflow",
"Print the first 2 paragraphs of https://modelcontextprotocol.io/introduction",
)
a = await handle.result()
print(a)
if __name__ == "__main__":
asyncio.run(main())