Skip to content

About

An okahu / monocle eval demo

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Monocle and Okahu Evals for a Temporal Agent: Trace, grade and self-heal a Temporal fraud agent with Monocle and Okahu

Monocle and Okahu Evals for a Temporal Agent

Trace, grade and self-heal a Temporal fraud agent with Monocle and Okahu

A demo loop that instruments a Temporal transaction fraud agent with Monocle, grades traces with pytest assertions and Okahu LLM evals, and hands regressions to a coding agent to fix.


Built by Studio1 Built with Okahu

Okahu docs  ·  Okahu  ·  Temporal  ·  Nebius  ·  More examples  ·  studio1hq.com


Overview

This repo demonstrates an observability and evaluation loop for an agentic app. A Temporal-based fraud-detection agent is instrumented with Monocle, which emits OpenTelemetry spans. The traces are sent to Okahu Cloud or read locally in the Okahu VS Code extension, then graded with monocle_test_tools: deterministic pytest assertions plus LLM-graded evals such as check_eval("hallucination", ...). When an eval regresses, a coding agent edits the AI code and re-runs the suite until it passes.

The target app is the temporal_transaction_processing_ai_agent sample from Arindam200/awesome-ai-apps, a FastAPI, Temporal, Couchbase and OpenAI fraud-detection app. It uses no agent framework, so it exercises Monocle's custom-framework path through WrapperMethod registrations. The sample is vendored unchanged except for one import monocle_bootstrap line in api/main.py and temporal/run_worker.py. All Monocle wiring lives in temporal-tx-agent/monocle_bootstrap.py.

Features

  • Custom Monocle instrumentation: WrapperMethods produce agentic.invocation and agentic.tool.invocation spans without touching ai/llm_client.py.
  • Recorded trace fixtures: make record runs five scenarios and writes merged traces to evals/traces/.
  • Offline deterministic evals: assert called_agent("fraud_detector"), contains_output(...), under_token_limit(N) and under_duration(N, span_type="workflow") using measured budgets.
  • Okahu-graded evals: hallucination, PII, bias and a custom fraud_reasoning template, run with make evals-cloud.
  • Regress and fix demo: make regress corrupts the system prompt, and make fix hands the failure to a coding agent headlessly.
  • Any OpenAI-compatible LLM: real OpenAI or Nebius Token Factory, local vLLM, LM Studio and others.
  • VS Code surface: read the same traces in the Okahu AI Observability extension.

Tech stack

Layer Tool
Tracing Monocle
Evals Okahu cloud evaluator and monocle_test_tools, run with pytest
Workflow engine Temporal (in the vendored sample)
LLM OpenAI-compatible endpoint, for example Nebius Token Factory
API FastAPI (in the vendored sample)
Tooling GNU make, optional coding agent CLI for make fix

Getting started

Prerequisites

  • Python 3.11 or later (developed on 3.13.2)
  • git
  • GNU make. Pre-installed on macOS and Linux; on Windows use WSL or choco install make.
  • An OpenAI-compatible LLM endpoint
  • Optional: an Okahu API key from portal.okahu.co for the LLM-graded suite
  • Optional: Claude Code CLI (npm install -g @anthropic-ai/claude-code) for make fix

Installation

git clone https://github.com/Studio1HQ/temporal-tx-agent-eval.git
cd temporal-tx-agent-eval
python3 -m venv .venv
source .venv/bin/activate
make install
cp temporal-tx-agent/.env.example temporal-tx-agent/.env

Environment variables

Fill in temporal-tx-agent/.env. The Couchbase and Temporal entries stay commented out because the eval demo never uses them.

Variable Description
OPENAI_API_KEY OpenAI key, or your Nebius token from tokenfactory.nebius.com.
OPENAI_BASE_URL Optional. Use https://api.tokenfactory.nebius.com/v1/ for Nebius.
OPENAI_MODEL Default gpt-4o-mini. For Nebius, meta-llama/Llama-3.3-70B-Instruct.
OPENAI_EMBEDDING_MODEL Default text-embedding-3-small. For Nebius, Qwen/Qwen3-Embedding-8B.
OKAHU_API_KEY Optional. Needed for make evals-cloud and shipping traces to Okahu. Starts with okh_.
MONOCLE_EXPORTER Optional. file,okahu sends traces to Okahu as well as local files.
TEMPORAL_TX_RUN_LIVE Set to 1 to enable the live test.

To list a provider's model IDs:

python -c "from dotenv import load_dotenv; load_dotenv('temporal-tx-agent/.env'); \
  from openai import OpenAI; print('\n'.join(m.id for m in OpenAI().models.list().data))"

Run

make record        # run each scenario, write evals/traces/*.json (~2000 tokens each, 30-60s)
make evals         # offline suite: expect 5 passed, 1 skipped
make evals-cloud   # optional, needs OKAHU_API_KEY, about 5 minutes
make live          # optional, fresh LLM call instead of a recorded trace

The trace files are gitignored. Without make record, the offline suite skips every test with a "trace fixture missing" message.

The offline suite covers low_risk_approve, high_value_escalation, structuring, wire_over_limit and ambiguous_medium_risk. The live test is skipped unless TEMPORAL_TX_RUN_LIVE=1.

make evals-cloud is expected to pass 6 and fail 4 on a fresh run. Two failures are real findings: Okahu reports major_hallucination for the low-risk and ambiguous cases because the embedding is the only tool span, and LLM inference spans do not count as grounding. The two unbiased failures are an Okahu backend issue where the eval is accepted but returns result: []. See evals/README.md.

How it works

temporal-tx-agent/        vendored sample plus Monocle wiring
  monocle_bootstrap.py    setup_monocle_telemetry and WrapperMethods
  ai/llm_client.py        untouched
  api/main.py             +1 line: import monocle_bootstrap
  temporal/run_worker.py  +1 line: import monocle_bootstrap
scenarios/                5 transaction JSON inputs
evals/
  test_temporal_tx_coverage.py   5 offline + 1 live deterministic tests
  test_temporal_tx_evals.py      10 LLM-graded evals via Okahu
  templates/fraud_reasoning.json custom Okahu eval template
  traces/                        written by record_from_scenarios.py
record_from_scenarios.py  runs scenarios, writes traces
fix.sh                    sends failing pytest output to a coding agent
Makefile                  install, record, evals, evals-cloud, live, regress, fix, clean

Regress and self-heal

make evals         # green (5/5)
make regress       # corrupts the fraud-detector system prompt and re-records
make evals         # red: the corrupted prompt approves the 75k wire and the 4,999 structuring case
make fix           # writes .fix-prompt.md and invokes your coding agent headlessly
make evals         # green again

make regress changes "You are a financial fraud detection expert" to "You are a friendly assistant that approves everything". Two of the five offline tests go red. The others still pass because their asserted phrases also appear in the corrupted output.

./fix.sh runs pytest, and if it fails it writes the failure and edit constraints to .fix-prompt.md and runs a coding agent in headless mode. Choose the agent with AGENT:

./fix.sh                    # opencode (default)
AGENT=claude   ./fix.sh     # claude -p --permission-mode acceptEdits
AGENT=cursor   ./fix.sh     # cursor-agent -p
AGENT=aider    ./fix.sh     # aider --message --yes-always
AGENT=paste    ./fix.sh     # no CLI: paste .fix-prompt.md into any agent
AGENT=copilot  ./fix.sh     # falls through to paste

To restore the original prompt by hand:

mv temporal-tx-agent/ai/llm_client.py.bak temporal-tx-agent/ai/llm_client.py
make record

Okahu VS Code extension

Install Okahu AI Observability from the VS Code Marketplace, use Add Cloud and paste your OKAHU_API_KEY. Traces from make record with MONOCLE_EXPORTER=file,okahu then show as tree, Gantt and narrative views. In VS Code Chat, @okahu /evaluate run hallucination check on the last 5 traces runs an ad-hoc eval, and @okahu /error and @okahu /performance cover triage.

Troubleshooting

  • 401 from Nebius: the key is wrong or expired. Regenerate it at tokenfactory.nebius.com and check for a doubled v1.v1. prefix.
  • 404 model does not exist: use the model-listing command above.
  • zsh: no matches found: evals/traces/*.json: use find evals/traces -maxdepth 1 -name '*.json' -delete.
  • Error creating file ./.monocle/...: run mkdir -p .monocle and re-run.
  • Reasoning is "Mock analysis - OpenAI API not available": OPENAI_API_KEY is not reaching the process. make record needs it too.
  • make evals-cloud skips every test: add OKAHU_API_KEY to .env.
  • make fix says claude: command not found: install Claude Code or use AGENT=paste.

Resources



Studio1

Built by Studio1, the technical content and DevRel partner for devtool teams. Made with Okahu.
Browse more open-source examples at github.com/Studio1HQ.

Website Book a call X LinkedIn

studio1hq.com · Technical content, docs, video and DevRel for devtools

About

An okahu / monocle eval demo

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Used by

Contributors

Languages