Example: Weather Agent
This example builds a fully functional weather agent with a custom Python capability that calls a weather API. By the end, you’ll have an agent package you can test locally and publish to the marketplace.
Project structure
Section titled “Project structure”Directoryweather-agent/
- agent.yaml
- agent.md
Directorycapabilities/
Directoryweather/
- manifest.yaml
- prompt.md
- Dockerfile
- requirements.txt
- server.py
Step-by-step
Section titled “Step-by-step”-
agent.yaml
agent.yaml name: weather-agentversion: 1.0.0display_name: Weather Agentdescription: Answers weather questions with real-time data.author: selu-exampleslicense: MITmodel:default: anthropic/claude-sonnettemperature: 0.5routing:mode: inlinetriggers:- keyword: weather- keyword: forecast- intent: weather_querypriority: 10capabilities:- name: weatherpath: ./capabilities/weathermemory:session_ttl: 1800max_history: 30long_term: false -
agent.md
agent.md You are Weather Agent, a helpful assistant that provides accurate,real-time weather information.## Instructions- Use the `weather_lookup` tool to answer any weather question.- Always ask for a location if the user doesn't provide one.- Report temperature, conditions, humidity, and wind speed.## Constraints- Only answer weather-related questions.- Never guess weather data — always use the tool. -
manifest.yaml
capabilities/weather/manifest.yaml name: weatherclass: tooldisplay_name: Weather Lookupdescription: Fetches current weather data from OpenWeatherMap.version: 1.0.0tools:- name: weather_lookupdescription: Get current weather conditions for a location.parameters:- name: locationtype: stringrequired: truedescription: City name (e.g. "Berlin") or coordinates ("52.52,13.405").- name: unitstype: stringrequired: falsedefault: metricdescription: "metric or imperial."resources:memory: 128Micpu: 0.25timeout: 10senv:- name: OPENWEATHER_API_KEYrequired: truedescription: Your OpenWeatherMap API key. -
server.py — the gRPC capability
capabilities/weather/server.py import grpc, json, os, requestsfrom concurrent import futuresimport capability_pb2 as pb2import capability_pb2_grpc as pb2_grpcAPI_KEY = os.environ["OPENWEATHER_API_KEY"]BASE_URL = "https://api.openweathermap.org/data/2.5/weather"class WeatherService(pb2_grpc.CapabilityServiceServicer):def Invoke(self, request, context):params = json.loads(request.parameters)location = params.get("location", "")units = params.get("units", "metric")try:resp = requests.get(BASE_URL, params={"q": location, "units": units,"appid": API_KEY,}, timeout=5)resp.raise_for_status()data = resp.json()result = {"location": data["name"],"temperature": data["main"]["temp"],"conditions": data["weather"][0]["description"],"humidity": data["main"]["humidity"],"wind_speed": data["wind"]["speed"],}return pb2.InvokeResponse(result=json.dumps(result), success=True)except Exception as e:return pb2.InvokeResponse(success=False, error=str(e))def serve():server = grpc.server(futures.ThreadPoolExecutor(max_workers=4))pb2_grpc.add_CapabilityServiceServicer_to_server(WeatherService(), server)server.add_insecure_port("[::]:50051")server.start()server.wait_for_termination()if __name__ == "__main__":serve() -
Dockerfile
capabilities/weather/Dockerfile FROM python:3.12-slimWORKDIR /appCOPY requirements.txt .RUN pip install --no-cache-dir -r requirements.txtCOPY . .USER 1000EXPOSE 50051CMD ["python", "server.py"] -
Test it
Terminal window export OPENWEATHER_API_KEY=your-key-hereselu dev .Open
http://localhost:4840and ask: “What’s the weather in Tokyo?”
Next steps
Section titled “Next steps”Ready to publish? Check the Marketplace Guidelines.