OrmaosDocs

Guides

LLM app

Record an app that calls a model API over HTTP and read how many requests it made, which ones failed and were retried, and which model answered.

View as Markdown

An app that calls a model makes HTTP requests and handles their errors. Ormaos records each request (method, host, port, path, status, duration) with the line of your code that made it, and every exception your code caught. Prompts and answers are values: recorded only with --values. The example is ai-app: ticket summaries from a local stand-in of a model API with two models, small-1 and large-1.

Record the app#

bash
ormaos run -- python app.py
ai-app
$ ormaos run -- python app.py
8 tickets summarized, summaries.json written
ormaos: r1 exit 0 in …: 1 Python process, 70 calls, 3 exceptions (3 swallowed), 112 io
ormaos: swallowed 3x urllib.error.HTTPError at app.py:28, raised at /tmp/ormaos-docs-python/cpython-3.14.4-linux-x86_64-gnu/lib/python3.14/urllib/request.py:611 [r1:e1]
ormaos: not collected: io: sockets, at model_server.py:51 (once): a socket was connected or bound there; sockets are not recorded, only HTTP made through http.client or httpx is
ormaos: saved in .ormaos/r1, next: ormaos exceptions r1:e1 | ormaos tree r1:c1

How many requests went to the model API?#

ai-app
$ ormaos io r1 --kind http
r1: 112 io events (file 101, http 11), showing http
  5x http POST http://127.0.0.1:…/v1/models/small-1/generate -> 200  at app.py:20 in ask  [r1:i3]
  3x http POST http://127.0.0.1:…/v1/models/small-1/generate -> 503  at app.py:20 in ask  [r1:i5]
  3x http POST http://127.0.0.1:…/v1/models/large-1/generate -> 200  at app.py:20 in ask  [r1:i6]
next: ormaos io r1:i3 | ormaos io r1:i5 | ormaos io r1:c8 | ormaos exceptions r1

Eleven requests for eight tickets: three to small-1 answered 503, and three went to large-1. One of the 503s:

ai-app
$ ormaos io r1:i5
r1:i5 http POST http://127.0.0.1:…/v1/models/small-1/generate -> 503
  caused at   app.py:20 in ask  [r1:c20]
  inside      r1:c1 <module> > r1:c4 main > r1:c19 summarize
  took        …
next: ormaos io r1:c20 | ormaos tree r1:c20 | ormaos io r1

Was a call retried after a caught error?#

ai-app
$ ormaos exceptions r1:e1
r1:e1 urllib.error.HTTPError: swallowed
  raised at   /tmp/ormaos-docs-python/cpython-3.14.4-linux-x86_64-gnu/lib/python3.14/urllib/request.py:611 in HTTPDefaultErrorHandler.http_error_default  [r1:c20]  (not your code; first seen at app.py:20 in ask)
  left calls   ask [r1:c20]
  handled at  app.py:28 in summarize  [r1:c19]  and not raised again
  message     not recorded; args: tuple[0]
  same type, same handler: 3 in all: r1:e1 r1:e2 r1:e3
next: ormaos tree r1:c19 | ormaos io r1:c19 | ormaos tree r1:c20 | ormaos exceptions r1:e2 | ormaos path r1:e1

The HTTPError was raised inside urllib, first seen at app.py:20 in ask, and handled at app.py:28 in summarize, which then called ask again:

ai-app
$ ormaos tree r1:c19
inside: r1:c1 <module> > r1:c4 main
r1:c19 summarize(base: str[22], ticket: dict[2]) -> str[55]  app.py:24  …  io 2  [swallowed 1x urllib.error.HTTPError: r1:e1]  calls below: 2
  r1:c20 ask(base: str[22], model: str[7], prompt: str[665]) -> raised  app.py:14  …  io 1
  r1:c25 ask(base: str[22], model: str[7], prompt: str[665]) -> str[55]  app.py:14  …  io 1
next: ormaos exceptions r1:e1 | ormaos tree r1:c4 | ormaos exceptions r1:c19

The first ask asked model: str[7] and raised; the second returned str[55]. The prompt is str[665]: its length, not its text.

With values#

To see which model each call asked for and what came back, record with --values. Use it on test data: the recording then holds data of the program.

bash
ormaos run --values -- python app.py
ai-app
$ ormaos tree r2:c19
inside: r2:c1 <module> > r2:c4 main
r2:c19 summarize(base: str[22]="http://127.0.0.1:…", ...) -> str[55]="The export to CSV leaves out the last day of the month."  app.py:24  …  io 2  [swallowed 1x urllib.error.HTTPError: r2:e1]  calls below: 2
  r2:c20 ask(base: str[22]="http://127.0.0.1:…", model: str[7]="small-1", ...) -> raised  app.py:14  …  io 1
  r2:c25 ask(base: str[22]="http://127.0.0.1:…", model: str[7]="large-1", ...) -> str[55]="The export to CSV leaves out the last day of the month."  app.py:14  …  io 1
next: ormaos exceptions r2:e1 | ormaos tree r2:c4 | ormaos exceptions r2:c19

Values are cut at 200 characters, and what looks like a secret is written ***. Prompts longer than the limit are shown cut, with their full length. See Shapes, not values.

Notes for LLM apps#

  • HTTP is seen for http.client (so also urllib, requests, urllib3) and httpx. A client that uses its own sockets, or gRPC, is not seen; sockets are listed in not collected.
  • Headers and bodies are never recorded, not even with --values; neither is the query string of a URL. An API key in a header stays out of the recording.
  • Which tool functions an agent ran, and in what order: ormaos tree r1, or ormaos tree r1 --function <name>.