Skip to content

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.

  • Directoryweather-agent/
    • agent.yaml
    • agent.md
    • Directorycapabilities/
      • Directoryweather/
        • manifest.yaml
        • prompt.md
        • Dockerfile
        • requirements.txt
        • server.py
  1. agent.yaml

    agent.yaml
    name: weather-agent
    version: 1.0.0
    display_name: Weather Agent
    description: Answers weather questions with real-time data.
    author: selu-examples
    license: MIT
    model:
    default: anthropic/claude-sonnet
    temperature: 0.5
    routing:
    mode: inline
    triggers:
    - keyword: weather
    - keyword: forecast
    - intent: weather_query
    priority: 10
    capabilities:
    - name: weather
    path: ./capabilities/weather
    memory:
    session_ttl: 1800
    max_history: 30
    long_term: false
  2. 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.
  3. manifest.yaml

    capabilities/weather/manifest.yaml
    name: weather
    class: tool
    display_name: Weather Lookup
    description: Fetches current weather data from OpenWeatherMap.
    version: 1.0.0
    tools:
    - name: weather_lookup
    description: Get current weather conditions for a location.
    parameters:
    - name: location
    type: string
    required: true
    description: City name (e.g. "Berlin") or coordinates ("52.52,13.405").
    - name: units
    type: string
    required: false
    default: metric
    description: "metric or imperial."
    resources:
    memory: 128Mi
    cpu: 0.25
    timeout: 10s
    env:
    - name: OPENWEATHER_API_KEY
    required: true
    description: Your OpenWeatherMap API key.
  4. server.py — the gRPC capability

    capabilities/weather/server.py
    import grpc, json, os, requests
    from concurrent import futures
    import capability_pb2 as pb2
    import capability_pb2_grpc as pb2_grpc
    API_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()
  5. Dockerfile

    capabilities/weather/Dockerfile
    FROM python:3.12-slim
    WORKDIR /app
    COPY requirements.txt .
    RUN pip install --no-cache-dir -r requirements.txt
    COPY . .
    USER 1000
    EXPOSE 50051
    CMD ["python", "server.py"]
  6. Test it

    Terminal window
    export OPENWEATHER_API_KEY=your-key-here
    selu dev .

    Open http://localhost:4840 and ask: “What’s the weather in Tokyo?”

Ready to publish? Check the Marketplace Guidelines.