Awesome Reviewers

Reviewer · AI

Agent context integrity

When agents or chains of agents rely on shared conversation history, injected messages, or instructional prompts to produce correct completions, treat that context as an explicit contract that must be scoped, complete, and verified end-to-end rather than assumed.

Instruction

When agents or chains of agents rely on shared conversation history, injected messages, or instructional prompts to produce correct completions, treat that context as an explicit contract that must be scoped, complete, and verified end-to-end rather than assumed.

Concretely:

  • Scope conversation/session state per invocation. If an object’s run() can be called multiple times, reset or isolate the conversation history at the start of each call so a later invocation never silently inherits turns from a previous, unrelated task.
    def run(self, task: str):
        self.conversation = Conversation()  # avoid leaking the previous run's turns
        self._initialize_agents(task)
        ...
    
  • When slicing or filtering history before sending it to an agent (e.g. dropping the “last turn”, building messages_for(...)), double-check which turns are actually required. Don’t blindly reuse a slicing helper from another component without verifying its assumptions hold here — a wrong slice can silently remove the one turn (the immediate prior output, or the original task) the prompt explicitly tells the agent to use.
  • Never assume a kwarg such as messages= is correctly forwarded through to the underlying LLM call just because a mocked/stubbed test passes. Add at least one test that exercises the real execution path (real Agent.run/llm.call) and asserts the expected turns actually reach the request payload.
  • Avoid writing prompt text that makes unverifiable claims about context (“the evaluation is in the conversation above”) unless it is guaranteed non-empty and correctly ordered at every call site. If the context could legitimately be empty or reordered, either assert non-emptiness defensively, fail loudly, or phrase the instruction so it degrades gracefully (e.g. “using any prior conversation if present”) instead of risking a hallucinated answer.
  • When an agent is handed a tool/schema that depends on auxiliary instructions (e.g. a director agent given an order-batch tool), ensure the matching instructional context (naming conventions, roster, protocol) is attached together with the tool — attaching only part of the required context produces plausible-looking but invalid tool calls.

The goal is that every agent call receives exactly the context it needs — no stale leakage from past runs, no silently dropped turns, no unverified assumptions about delivery or ordering.</description> </invoke>