Compare commits
2 Commits
b6658fc6f2
...
13c9b97073
| Author | SHA1 | Date | |
|---|---|---|---|
| 13c9b97073 | |||
| 91cdb1328b |
29
main.py
Normal file
29
main.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import asyncio
|
||||
|
||||
from mcp_agent.app import MCPApp
|
||||
from mcp_agent.agents.agent import Agent
|
||||
from mcp_agent.workflows.llm.augmented_llm_openai import OpenAIAugmentedLLM
|
||||
|
||||
|
||||
app = MCPApp(name="weather_agent")
|
||||
|
||||
|
||||
async def main():
|
||||
async with app.run():
|
||||
agent = Agent(
|
||||
name="weather",
|
||||
instruction=(
|
||||
"Ты ассистент по погоде. "
|
||||
"Если нужны актуальные данные — используй доступные инструменты."
|
||||
),
|
||||
server_names=["weather"],
|
||||
)
|
||||
|
||||
async with agent:
|
||||
llm = await agent.attach_llm(OpenAIAugmentedLLM)
|
||||
answer = await llm.generate_str("Какая сейчас точная погода в Берлине?")
|
||||
print(answer)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
11
mcp_agent.config.yaml
Normal file
11
mcp_agent.config.yaml
Normal file
@@ -0,0 +1,11 @@
|
||||
execution_engine: asyncio
|
||||
|
||||
mcp:
|
||||
servers:
|
||||
weather:
|
||||
command: "python"
|
||||
args: ["weather_mcp.py"]
|
||||
|
||||
openai:
|
||||
base_url: "http://localhost:11434/v1"
|
||||
default_model: "qwen3:1.7b"
|
||||
2
mcp_agent.secrets.yaml
Normal file
2
mcp_agent.secrets.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
openai:
|
||||
api_key: "ollama"
|
||||
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
mcp-agent[openai]
|
||||
mcp
|
||||
pydantic
|
||||
29
weather_mcp.py
Normal file
29
weather_mcp.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class WeatherResult(BaseModel):
|
||||
city: str
|
||||
temperature: int
|
||||
units: str
|
||||
condition: str
|
||||
|
||||
|
||||
server = FastMCP(name="weather")
|
||||
|
||||
|
||||
@server.tool(
|
||||
name="get_weather",
|
||||
description="Возвращает актуальную погоду по городу",
|
||||
)
|
||||
async def get_weather(city: str, units: str = "metric") -> WeatherResult:
|
||||
return WeatherResult(
|
||||
city=city,
|
||||
temperature=18,
|
||||
units=units,
|
||||
condition="partly cloudy",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
server.run()
|
||||
Reference in New Issue
Block a user