Enable telemetry in your service
Add two lines at startup before you create yourServiceHost:
Python
Example: Weather Toolkit with custom instrumentation
The example adds custom spans around validation, the external HTTP call, and response parsing. It also adds logs and metrics.Custom Spans
Use spans to track a specific operation in trace. Spans can help you understand timing for each step and attach attributes/events to make debugging easier. This example records:toolkit.execute(created by MeshAgent) this is the high-level tool call including information about which tool was called and what information was passed to the toolvalidate_input– checks city/units, adds events for pass/failfetch_weather_api– the external HTTP call with:http.url,http.method,http.status_code,http.response_size- events like
api_request_start,api_request_success,api_timeout,rate_limit_exceeded
parse_response– extracts the fields you return to the caller
Python
Custom Logs
otel_config() sets up an OTEL logging handler so your normal logging.info() lines are captured. Add extra logs to make it easier to debug and understand…
Python
Custom Metrics
You can also add additional counters and historgrams to help track trends over time.Python
Running the sample
You can run this toolkit as a service and invoke the weather tool,get_weather(), from Studio or the CLI.
Step 1: Creating the room service
First build and push the container, then add the service to your room. You’ll need aDockerfile and meshagent.yaml file to do so.
Dockerfile
yaml
- Click the menu icon for the room —> Services —> New Service
- Fill in name, image details, and port details. For Ports you can put
*to let MeshAgent assign an available port.- Add the port endpoint information e.g. Port Type:
meshagent.callable, Endpoint:/weather, Participant Name”weather-toolkit.
- Add the port endpoint information e.g. Port Type:
- Create the service
Step 2: Invoking the tool
Once you’ve created the service you can invoke the tool directly from MeshAgent Studio by going into the room, clicking the menu icon, selecting Toolkits, then select the Weather Tool and click Invoke. The UI will display a dialog for you to input the city and units you want to get the weather from. You can also invoke the tool using the MeshAgent CLI:bash
Viewing telemetry
From MeshAgent Studio you will see Logs, Traces, and Metrics both from the Session view of the room and from the Developer Console. The Session viewer provides a focused view of session details which are accessible during and after each session. The Developer Console appears on the lower part of the screen once you’re inside a room and shows live traces, logs, and metrics as you interact with your services inside a room. After invoking the weather tool in this example you should see a trace tree appear in the Traces tab with a structure like this:Next Steps
- Agents: Understand how agents work in MeshAgent and start building your first one!
- Tools: Learn how to build tools human and agent participants can use inside a MeshAgent room.
- Services & Containers: Learn how to deploy instrumented agents and tools as project wide or room specific services in MeshAgent