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.

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.

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.

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.

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.

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.

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.

Within Agentevals#

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

  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.

  3. Choose what type of scoring you want to use for your evaluation.

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