kagent

Instrumenting Agentic Observability in Kagent + Agent Substrate#

503's, a Worker Node goes down, a cluster needs to be scaled due to limited hardware capacity, a memory leak is causing a significant amount of RAM use…

These are all of the things Platform/DevOps engineers and SREs see today, but how does what you're used to monitoring and observing change in the agentic era?

In this blog post, you'll learn what you need to think about for observability with AI and how to do it with kagent + Agent Substrate.

The Reality Of Observability Today#

There was a time not too long ago where you'd walk into an organization and in a big room somewhere within the building, there were engineers sitting at desks with humongous monitors/TVs across the wall. What was on these monitors/TVs was the soul of the organization. Every piece of network traffic that you can think of ranging from what's coming to and leaving a server, fiber routes, regional outages, network spikes, traffic incoming through the firewall, and every other packet for ingress and egress.

Although we don't see as many NOCs due to remote work and modern alert tooling, these are still the patterns we know by heart.

The incidents you know by heart in Kubernetes before agents, four failures and four signals: the app falls over (HTTP 503, CrashLoopBackOff), a node goes down (NodeNotReady, OOMKilled), memory creeps up (RSS +2% every hour), and access is denied (403 Forbidden, RBAC denied). An event log shows every signal mapping to a playbook.

And right when the industry became comfortable with understanding the ins and outs of packets flowing through the cloud, SaaS, and DevOps infrastructure, the tech overlords saw we were all getting too comfortable, said "let's throw a wrench into things" and along came Agentic AI.

The fortunate part to that, however, is that 99% of what the industry has learned about monitoring and observability carry over to the world of agentic in the best possible ways.

Then the agent shipped: one support agent run told as two stories. The dashboards said healthy (pod Running, HTTP 200 OK, p99 latency 410 ms, 0.0% error rate), while what actually happened is the agent answered a refund question with the shipping policy, never saw the refund tool it needed, looped through 14 LLM calls, and burned 212k tokens on one question.

Agentic Observability#

When you're running an Agent and agentic/inference infrastructure, the same rules apply to Platform/DevOps engineering observability best practices.

  • Understanding the system/platform health
  • Know how your workload (in this case, an Agent) is performing
  • Is the cluster/system reachable
  • Are the endpoints reachable

And everything in-between. However, there are a few new things you need to consider when observing agentic.

Eight questions agentic observability has to answer: did it perform as expected, how do we evaluate runs, is it going rogue, where did the request go, did the LLM have enough context, is the sandbox healthy, what can it access, and what did it cost.

A lot of what you'll see in observing agentic, aside from the four bullet points above, is token usage, performance (both in the "did the Agent do as expected?" category and inference performance), ingress/egress to the sandbox, and context usage/compression/context efficiency.

A 4.2 second agent trace broken into spans (invoke_agent support, chat plan, mcp tools/list, execute_tool get_order, invoke_agent billing over A2A, chat answer, and the sandbox pod), each mapped to the questions it answers, with the gen_ai.operation.name, gen_ai.request.model, gen_ai.usage.input_tokens, and gen_ai.tool.name attributes.

What you're already looking at in a monitoring/observability platform is already great and necessary for agentic workloads, you'll just need to map to different resources for Agents, agentic workflows, and agentic/inference infrastructure.

A table mapping what you already watch to its agent-world twin: a crashed process to a failed or abandoned agent run, a memory leak to context bloat and runaway token use, 403 / RBAC denied to a denied or over-privileged tool call, a trace across services to a trace across agent, LLM, MCP tools and other agents, p99 latency to time to first token, tool latency and run duration, error budgets and SLOs to eval-score SLOs, and capacity planning to token budgets and cost per run.

Implementing The Stack#

With the "why" and the "what" answered in the previous sections, let's get down to the hands-on equation of how the observability stack will be implemented.

The stack that will get observed is:

  • kagent
  • Agent Substrate
  • agentgateway that runs in Agent Substrate for ingress and egress.

The data will show traces, metrics, and logs for everything from the proxy routers ingress/egress to Agent invocations, tool executions, and evaluation results.

Tracing, Logs, and Metrics#

The first step is to get the observability stack up. For this, you can use the Grafana/Prometheus/Loki/Tempo stack.

  1. Save the following value files and manifests in an appropriate location for you to use:

  2. Run the following to create the Namespace for your observability stack to live and install the observability stack.

    kubectl create namespace telemetry
    helm upgrade --install tempo tempo \
    --repo https://grafana.github.io/helm-charts \
    -n telemetry -f values/tempo.yaml --wait
    helm upgrade --install loki loki \
    --repo https://grafana.github.io/helm-charts \
    -n telemetry -f values/loki.yaml --wait
    helm upgrade --install kube-prometheus-stack kube-prometheus-stack \
    --repo https://prometheus-community.github.io/helm-charts \
    -n telemetry -f values/kube-prometheus-stack.yaml --wait
    helm upgrade --install otel-collector opentelemetry-collector \
    --repo https://open-telemetry.github.io/opentelemetry-helm-charts \
    -n telemetry -f values/otel-collector.yaml --wait
    kubectl apply -f manifests/otel-collector-servicemonitor.yaml
    kubectl apply -f manifests/agentgateway-podmonitor.yaml

You should now see your observability stack running.

> kubectl get pods -n telemetry
NAME READY STATUS RESTARTS AGE
kube-prometheus-stack-grafana-76fc848b47-z8p59 3/3 Running 0 2d
kube-prometheus-stack-kube-state-metrics-645c589fb6-c4rfn 1/1 Running 0 2d
kube-prometheus-stack-operator-6bd8895578-nqhkb 1/1 Running 0 2d
loki-0 2/2 Running 0 2d
otel-collector-76896b7bb7-2pbkm 1/1 Running 0 47h
prometheus-kube-prometheus-stack-prometheus-0 2/2 Running 0 2d
tempo-0 1/1 Running 0 2d

Evaluations#

The next step is to install and configure agentevals. The values file agentevals.yaml turns on evaluation events and sends them to the OTel collector. Each score lands in Loki as a gen_ai.evaluation.result event that carries the trace and span ID of the Agent turn.

For evals to use "LLM as the judge", you will need an LLM API key (and you'll need it to use Agents regardless). Because of that, OpenAI is used for this, but you can use any provider you'd like.

kubectl create namespace agentevals
kubectl get secret default-model-config -n kagent -o jsonpath='{.data.OPENAI_API_KEY}' | base64 -d \
| kubectl create secret generic agentevals-judge -n agentevals --from-file=OPENAI_API_KEY=/dev/stdin
helm upgrade --install agentevals oci://ghcr.io/agentevals-dev/agentevals/helm/agentevals \
--version 0.15.1 -n agentevals \
-f values/agentevals.yaml --wait

You should see agentevals running in the agentevals Namespace.

> kubectl get pods -n agentevals
NAME READY STATUS RESTARTS AGE
agentevals-86d766977f-rj9xf 1/1 Running 0 46h

The Collector's traces/agentevals and logs/agentevals pipelines in otel-collector.yaml send agent telemetry to agentevals. Until agentevals is installed, the Collector logs export errors for them. Those pipelines only forward telemetry from agent runtimes (resources with kagent.runtime)

Agent Substrate and kagent Collector#

With the observability stack and agentevals up and running, you can now point Agent Substrate and kagent at the OTel Collector.

helm upgrade substrate oci://ghcr.io/kagent-dev/substrate/helm/substrate \
--version 1.0.1 -n ate-system \
-f values/substrate.yaml --wait --timeout 10m
OTEL=http://otel-collector.telemetry.svc.cluster.local:4317
helm upgrade kagent oci://ghcr.io/kagent-dev/kagent/helm/kagent \
--version "$(helm get metadata kagent -n kagent -o json | jq -r .version)" \
-n kagent --reuse-values \
--set-string config.telemetry.traces.endpoint=$OTEL \
--set-string config.telemetry.metrics.endpoint=$OTEL \
--set-string config.telemetry.logs.endpoint=$OTEL \
--set-string config.runtimeDefaults.telemetry.traces.endpoint=$OTEL \
--set-string config.runtimeDefaults.telemetry.metrics.endpoint=$OTEL \
--set-string config.runtimeDefaults.telemetry.logs.endpoint=$OTEL \
--set config.runtimeDefaults.telemetry.captureContent=true \
--wait

Seeing Observability In Action#

The good news about what you installed in the previous section is, as a Platform/DevOps engineer, most likely very familiar. The Grafana/Prometheus/Loki/Tempo stack has been an open-source stack around the industry for a long while and battle tested.

With that, the same thought process you have with the rest of your infrastructure will tie in nicely to the agentic observability world.

New dashboard, same instincts, the golden signals for agents: latency, traffic, errors, and saturation carry over, and quality (eval score per run, tracked as an SLO) is the only new one. An example agent SLO reads: 95% of support-agent runs score at least 0.8, over 28 days.

Within The Observability Stack#

  1. Open up all of the dashboards.

    kubectl port-forward -n kagent svc/kagent-ui 8081:8080 # kagent UI
    kubectl port-forward -n kagent svc/kagent-controller 8083:8083 # kagent CLI
    kubectl port-forward -n agentevals svc/agentevals 8001:8001 # agentevals UI
    kubectl port-forward -n telemetry svc/kube-prometheus-stack-grafana 3000:80 # Grafana
  2. Generate traffic so there are sessions that come up in the observability stack and agentevals.

    AGENTS=(smoke-agent)
    RUNS=2
    for agent in "${AGENTS[@]}"; do
    for run in $(seq 1 "$RUNS"); do
    session=$(kagent agent session create --agent "$agent" -o json | jq -r .session.id)
    echo "== $agent run $run ($session)"
    kagent agent invoke --session "$session" \
    -t "Use your tools to list the namespaces in this cluster, then tell me how many pods are running in the kagent namespace. Answer in two short sentences."
    kagent agent invoke --session "$session" \
    -t "Now use your tools to list the services in the agentevals namespace. One sentence."
    done
    done
  3. After the run, go to Explore in Grafana and use both Tempo and Loki as the data source. You'll be able to see everything from the Agent turns to the Agent Substrate calls to the traffic flowing through agentgateway and everything in-between.

    Grafana Explore with the Tempo data source and a TraceQL query for the smoke-agent invoke_agent spans, returning four traces from the kagent-controller service.
    A single trace opened in Grafana Tempo with 150 spans across 6 services: kagent-controller, agentgateway, the Agent Substrate API, and the smoke-agent A2A request.
    Grafana Explore with the Loki data source filtered to the agentgateway service, showing the logs volume and an access log line for an A2A SendStreamingMessage request routed to the Agent Substrate router.

Within Agentevals#

  1. Go into agentevals and click on the Local Development button.

    The agentevals Live Agent Sessions page under Local Development, showing two completed sessions, each with Queue and Set as EvalSet buttons.
  2. You'll see the two completed sessions. Choose whichever one and click the Set as EvalSet button. You'll see the purple Continue to Evaluation button pop up, click that.

    agentevals with one session selected as the golden run and the purple Continue to Evaluation button displayed above the completed sessions.
  3. Choose what type of scoring you want to use for your evaluation.

    The agentevals Evaluations page with two trace files loaded, the eval set file, and the built-in evaluator configuration: tool_trajectory_avg_score under Trajectory, and response_evaluation_score, response_match_score, and final_response_match_v2 under Response.

You'll now be able to see the full score of your evaluation against your two agent turns/runs.

The agentevals Evaluation Results page showing total traces, pass rate, and average score, with a chart of p50, p95, and p99 latency across traces.