3.2 Build and inspect a small agent
Implement a constrained loop before connecting any external model.
Start with the smallest testable system
Before adding a provider or framework, make the control flow explicit. The original Python example below uses a deterministic planner as a stand-in for a model. It is a working demonstration of a bounded tool loop, not an LLM-powered scientific agent.
The sequence is deliberately invented. The tool checks its alphabet and reports length. It cannot draw conclusions about function, structure or drug discovery.
Run an original agent-loop scaffold
Copy this into a Python notebook or a local .py file. It needs only the standard library and makes no external requests.
import json
def sequence_length(sequence):
allowed = set("ACDEFGHIKLMNPQRSTVWY")
sequence = sequence.strip().upper()
if not sequence or len(sequence) > 10000:
raise ValueError("Sequence length outside demo limits")
if set(sequence) - allowed:
raise ValueError("Unexpected amino-acid symbol")
return {"length": len(sequence), "sequence": sequence}
def planner(state):
if not state["observations"]:
return {"tool": "sequence_length", "sequence": state["sequence"]}
return {"final": state["observations"][-1]["length"]}
state = {"sequence": "ACDEFGHIK", "observations": []}
for step in range(3):
action = planner(state)
if "final" in action:
print("Final length:", action["final"])
break
if action.get("tool") != "sequence_length":
raise ValueError("Tool not allowed")
observation = sequence_length(action["sequence"])
state["observations"].append(observation)
print(json.dumps({"step": step, "action": action,
"observation": observation}))
else:
raise RuntimeError("Step budget exhausted")What changes when the planner is a model?
A real model may return malformed arguments, request an unavailable tool or keep asking for another step. Validate its structured response before execution. Keep the tool allowlist and step limit in software.
Public agent-framework documentation can help you explore implementations beyond this scaffold. Some examples require provider accounts and paid API access; do not paste credentials into this site.
Further reading
Original reference materials. External notebooks run on their own services, not on this site.