agent.py hinzugefügt
This commit is contained in:
@@ -0,0 +1,55 @@
|
|||||||
|
import json
|
||||||
|
from llm import ask_llm
|
||||||
|
from mcp_client import MCPClient
|
||||||
|
|
||||||
|
mcp = MCPClient()
|
||||||
|
|
||||||
|
SYSTEM = """
|
||||||
|
Du bist JARVIS, ein Smart-Home Assistent.
|
||||||
|
|
||||||
|
Du kannst MCP Tools verwenden.
|
||||||
|
|
||||||
|
Wenn du ein Tool benutzen willst, antworte exakt im JSON Format:
|
||||||
|
|
||||||
|
{
|
||||||
|
"tool": "tool_name",
|
||||||
|
"args": { }
|
||||||
|
}
|
||||||
|
|
||||||
|
Wenn kein Tool nötig ist:
|
||||||
|
|
||||||
|
{
|
||||||
|
"response": "Text"
|
||||||
|
}
|
||||||
|
|
||||||
|
Beispiele Tools:
|
||||||
|
- openhab.items.set
|
||||||
|
- openhab.items.get
|
||||||
|
"""
|
||||||
|
|
||||||
|
def run_agent(user_input):
|
||||||
|
|
||||||
|
messages = [
|
||||||
|
{"role": "system", "content": SYSTEM},
|
||||||
|
{"role": "user", "content": user_input}
|
||||||
|
]
|
||||||
|
|
||||||
|
response = ask_llm(messages)
|
||||||
|
|
||||||
|
try:
|
||||||
|
data = json.loads(response)
|
||||||
|
|
||||||
|
if "tool" in data:
|
||||||
|
result = mcp.call_tool(data["tool"], data["args"])
|
||||||
|
|
||||||
|
followup = ask_llm([
|
||||||
|
{"role": "system", "content": "Formuliere eine natürliche Antwort aus diesem Ergebnis."},
|
||||||
|
{"role": "user", "content": str(result)}
|
||||||
|
])
|
||||||
|
|
||||||
|
return followup
|
||||||
|
|
||||||
|
return data["response"]
|
||||||
|
|
||||||
|
except:
|
||||||
|
return response
|
||||||
Reference in New Issue
Block a user