PTENES
MODULE 1.4

💬 Conversational loop

Build the observe, decide, execute, and respond cycle without losing state, control, or transparency.

6

Topics

3h

Load

Agent Developer

Level

Orchestration

Type

0 of 60%
1

Define the turn state

What it is: Each turn brings together the message, page snapshot, catalog, previous executions, and remaining budget.

Why learn: An explicit state prevents prompts from being assembled through accidental concatenation.

Observe context starting state Decide + act observable decision Respond + continue verifiable result

Before modeling

Write the person’s request, the current state, and the evidence that will prove completion.

Starting error

Starting with a function name or a button produces a tool without a clear human goal.

Predict before opening the code

What information changes the decision? What effect needs to appear in the interface? Answer before implementing.

const turn = { message, pageState, tools, calls: [], budget: { maxCalls: 4 } };
Going deeper: evidence worth keeping

Record the input, previous state, decision made, result, and visible change to the page.

Also include an induced failure and the observed behavior without WebMCP support.

Key concepts

01

turn state

02

page snapshot

03

history

04

budget

2

Implement observe, decide, act

What it is: The loop alternates structured observation, model decision, and controlled execution until it reaches a terminal state.

Why learn: Separating phases makes testing easier and prevents unbounded recursion.

QuestionStrong contractWeak contract
When should you use it?The description names the intent and context.“Does things” or “manages.”
What does it receive?Only the data you need.Generic and unlimited object.
What does it return?Verifiable state and next action.Text without a protocol.
How does it fail?Code, rationale, and recovery.Opaque exception.

Do it

  • ✓ Use specific verbs.
  • ✓ Define the inputs.
  • ✓ State the evidence.

Avoid

  • ✗ Mix intentions.
  • ✗ Accept any object.
  • ✗ Hide effects.
while (!turn.done && turn.calls.length < turn.budget.maxCalls) {
  turn.next = await decide(observe(turn));
  await act(turn.next, turn);
}
Going deeper: evidence worth keeping

Record the input, previous state, decision made, result, and visible change to the page.

Also include an induced failure and the observed behavior without WebMCP support.

Key concepts

01

observe

02

decides

03

act

04

terminal

3

Manage multiple calls

What it is: A task may require search, details, and action, with results informing later decisions.

Why learn: The runtime must preserve dependencies without letting the model invent an intermediate ID.

1

Observe

Capture state, input, and context before taking action.

2

Decide

Validate preconditions and choose the allowed transition.

3

Execute

Apply the shared rule and respect cancellation.

4

Prove

Update the interface and return a structured result.

Checkpoint

If step 2 fails, the tool doesn’t try to “make it work”: it returns an explicit recovery.

const courseId = calls.buscar_cursos.output.items[0].id;
await propose("consultar_curso", { courseId });
Going deeper: evidence worth keeping

Record the input, previous state, decision made, result, and visible change to the page.

Also include an induced failure and the observed behavior without WebMCP support.

Key concepts

01

dependency

02

result binding

03

sequence

04

parallel safety

4

Pause for the human

What it is: Ambiguity, high risk, or a material change of plan creates a confirmation checkpoint.

Why learn: The pause preserves human agency without breaking the continuity of the turn.

REFERENCE CODE

return pause({ reason: "MULTIPLE_MATCHES", choices, resumeToken });
Input

It is small, described, and validatable.

Execution

Reuses the application's actual rule.

Output

Allows you to verify the effect and continue.

Read the code as a contract

Underline where input is validated, where the effect occurs, where cancellation arrives, and where the UI is updated.

Going deeper: evidence worth keeping

Record the input, previous state, decision made, result, and visible change to the page.

Also include an induced failure and the observed behavior without WebMCP support.

Key concepts

01

human in the loop

02

ambiguity

03

risk

04

resume token

5

Respond with evidence

What it is: The response distinguishes what was observed, what was executed, and what still depends on the user.

Why learn: Transparency reduces false claims of success and builds trust.

Induced failure

Run the scenario with missing state, invalid input, or unavailable capability.

Expected recovery

The response explains what failed, what remains safe, and what action can continue.

Minimum test matrix

✓ reproducible happy path

✓ actionable invalid input

✓ cancellation ends the work

✓ fallback preserves the user journey

✓ interface reflects the state

✓ backend maintains authorization

return answer({ found: 3, executed: [], pending: "escolha um curso", evidence: trace.links });
Going deeper: evidence worth keeping

Record the input, previous state, decision made, result, and visible change to the page.

Also include an induced failure and the observed behavior without WebMCP support.

Key concepts

01

grounding

02

executed effects

03

pending action

04

citation

6

Evaluate the full conversation

What it is: The test measures completion, correct tool, steps, safety, recovery, and response quality.

Why learn: Evaluating only the final text hides unnecessary or dangerous calls.

Synthesis exercise

  1. 1. Explain the problem without using the name of the technology.
  2. 2. Design the before and after states.
  3. 3. Implement the smallest functional proof.
  4. 4. Trigger a failure and record the recovery.
  5. 5. Deliver code, evidence, and a known limitation.

Module challenge

Deliver a Page Agent that resolves a multi-step search, requests confirmation, and explains the result with evidence.

Responsible Agent Developer criterion

The deliverable must work, explain its limitations, and preserve the human path when the experimental capability is unavailable.

score = success * 40 + correctTools * 25 + safety * 25 + clarity * 10;
Going deeper: evidence worth keeping

Record the input, previous state, decision made, result, and visible change to the page.

Also include an induced failure and the observed behavior without WebMCP support.

Key concepts

01

task success

02

tool accuracy

03

step count

04

safety

📦 Module delivery

Deliver a Page Agent that resolves a multi-step search, requests confirmation, and explains the result with evidence.

Acceptance criteria

The deliverable works with WebMCP support and preserves the manual path when the API is unavailable.

Evidence

Include code, a tested scenario, the observed result, and a known limitation.

Technical sources