Create agent.py
Browse files
agent.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Import smolagents
|
| 2 |
+
from smolagents import ToolCallingAgent, ToolCollection, LiteLLMModel
|
| 3 |
+
from mcp import StdioServerParameters
|
| 4 |
+
|
| 5 |
+
# Specify agricultural-focused LLM
|
| 6 |
+
model = LiteLLMModel(
|
| 7 |
+
model_id="ollama_chat/qwen2.5:14b",
|
| 8 |
+
num_ctx=8192
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
# Configure connection to crop optimization server
|
| 12 |
+
server_parameters = StdioServerParameters(
|
| 13 |
+
command="uv",
|
| 14 |
+
args=["run", "server.py"],
|
| 15 |
+
env=None,
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
# Initialize agent with crop optimization tools
|
| 19 |
+
with ToolCollection.from_mcp(server_parameters, trust_remote_code=True) as tool_collection:
|
| 20 |
+
agent = ToolCallingAgent(
|
| 21 |
+
tools=[*tool_collection.tools],
|
| 22 |
+
model=model,
|
| 23 |
+
system_prompt="You are an agricultural AI assistant specialized in crop optimization."
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# Example agricultural queries
|
| 27 |
+
agent.run("What are the optimal growing conditions for cabbage?")
|
| 28 |
+
agent.run("Predict green pepper yield in KZN region")
|
| 29 |
+
agent.run("What pests commonly affect tomato crops?")
|
| 30 |
+
agent.run("Recommend crops suitable for clay soil in tropical climates")
|