Created
December 11, 2025 17:30
-
-
Save Proteusiq/fdac6cad74ee2990174428493404aa24 to your computer and use it in GitHub Desktop.
encomplete example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import NamedTuple | |
| from smolagents import CodeAgent, LiteLLMModel, Tool | |
| class Coordinates(NamedTuple): | |
| latitude: float | |
| longitude: float | |
| model = LiteLLMModel( | |
| model_id="ollama/qwen3:latest", | |
| temperature=0.2, | |
| api_base="http://localhost:11434", | |
| ) | |
| class GeoLocation(Tool): | |
| name = "geolocation_tool" | |
| description = """ | |
| Convert a human-readable address into geographic coordinates. | |
| Returns latitude and longitude as a dictionary. | |
| """ | |
| inputs = { | |
| "address": { | |
| "type": "string", | |
| "description": "Any address, e.g. 'Tivoli, Copenhagen' or 'Egedalsvej 14, 2590'.", | |
| } | |
| } | |
| output_type = "object" | |
| def forward(self, address: str) -> dict: | |
| address_clean = "+".join(address.split()) | |
| print(f"[GeoLocation] Received address: {address_clean}") | |
| # example returned object | |
| location = Coordinates(latitude=55.4, longitude=12.3) | |
| return {"latitude": location.latitude, "longitude": location.longitude} | |
| class WeatherReport(Tool): | |
| name = "weather_report_tool" | |
| description = """ | |
| Return a simple weather report for a given set of coordinates. | |
| Input: latitude and longitude as numbers. | |
| Output: a human-readable weather summary. | |
| """ | |
| inputs = { | |
| "latitude": { | |
| "type": "number", | |
| "description": "Latitude of the location.", | |
| }, | |
| "longitude": { | |
| "type": "number", | |
| "description": "Longitude of the location.", | |
| }, | |
| } | |
| output_type = "string" | |
| def forward(self, latitude: float, longitude: float) -> str: | |
| print(f"[WeatherReport] DEBUG: latitude={latitude}, longitude={longitude}") | |
| # to be replaced with real weather API logic | |
| return f"The weather at {latitude},{longitude} is rainy at the moment." | |
| agent = CodeAgent( | |
| tools=[GeoLocation(), WeatherReport()], | |
| model=model, | |
| stream_outputs=True, | |
| ) | |
| if __name__ == "__main__": | |
| while True: | |
| query = input("> ") | |
| agent.run(query) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment