Skip to content

Latest commit

 

History

History
92 lines (63 loc) · 2.6 KB

react.md

File metadata and controls

92 lines (63 loc) · 2.6 KB

Reason with observations

The problem

A pharmacy parcel never reached the patient. Records point to other records, such as a driver log or a swap note.

The first try has the same tool and the same step limit. It looks things up without saying why. It gets no nudge when it repeats itself. We wanted to see if reasons help.

How it works

Trace a lost parcel one record at a time.

This is ReAct, an agent loop. The model gives a reason, uses a lookup tool and reads the result.

  1. The model says why it wants a record, then asks for it.
  2. Code returns the record. This is the observation.
  3. The model reads it and picks the next lookup.
  4. A repeat lookup gets a nudge, so the loop moves on.

For example, the driver log names a swap note. Only then can the model ask for it.

The flow

sequenceDiagram
    participant App as Your code
    participant Model
    loop until it can answer
        Model->>App: reason and lookup
        alt the record is new
            App-->>Model: the record
        else it was read before
            App-->>Model: look somewhere new
        end
    end
    Model-->>App: where the parcel is
Loading

Concepts

Run it

uv run lab react naive
uv run lab react

Add --case 2 or --case 3 to try the other cases.

Prove it

There are three lost parcels. Code checks that the answer names the true place.

Version Parcels traced
Act only 3
Reason, then act 3

The pattern did not win. Both versions traced every parcel.

Now break it. Open the pattern file and find observe. Make it return the record every time. Then run the test:

uv run pytest tests/promises/test_react.py

The test fails, because the same record can be read again with no nudge.

Stuck points

  • A "no key found" message means the key file is missing. Copy the example file and paste your key.
  • If you see "no answer within the step limit", the trail was longer than the limit.

What to watch for

These trails are clear, with each record naming the next. A messy trail may treat the two versions differently. That was not measured.

Every turn sends the history again, so long trails cost more.

Where to go next

Go to Verify every step. It checks that each move really worked.