← Back to learning path
Chapter · Published

AI agent foundations: tasks, state, and boundaries

Understand how agents differ from ordinary chat and build a minimal loop with explicit state and permission boundaries.

Source: knowledge/p24-b/collection_8023a8d754046b6c2ae7220f/tutorials/agent-foundations-and-boundaries.mdAI agent engineering
Chapter progress 0%Learning path progress 0% · 0/10 chapters completedContinue learning path →

An AI agent is a loop in which a model proposes the next action, a program executes it, and the result is fed back. The important boundary is not giving the model broad access; it is expressing tools, argument validation, state, and stop conditions as code contracts.

Core concepts

Break one run into six stages: input, plan, tool call, observation, next action, and completion. The model may propose an action, but the server validates permissions, argument ranges, and idempotency keys. Store state as an event list so a run can be replayed and audited.

Runnable example

from dataclasses import dataclass

@dataclass
class ToolCall:
    name: str
    args: dict

ALLOWED_TOOLS = {'lookup_ticket'}

def validate(call: ToolCall) -> None:
    if call.name not in ALLOWED_TOOLS:
        raise ValueError('tool is not allowed')
    if set(call.args) != {'ticket_id'}:
        raise ValueError('invalid arguments')
    if not str(call.args['ticket_id']).startswith('T-'):
        raise ValueError('invalid ticket id')

Steps

  1. Draw the state transition diagram and mark nodes that may run automatically versus nodes requiring human confirmation.
  2. Define JSON input, return values, timeouts, and error types for every tool, then validate again on the server.
  3. Set a maximum step count and total duration. Return an explainable paused state at the limit.
  4. Record the model version, tool name, parameter summary, and result status. Never record tokens or complete customer text.

When to use it

This pattern suits ticket classification, information lookup, and code review. It should not directly replace payment, permission grants, or irreversible production actions.

Common questions

How do I avoid loops? Use step, time, and repeated-action limits together.

Can a model write to a database directly? It should not. Use a restricted service function and an idempotency key.

How should a failure recover? Mark the run as paused, preserve its events, and offer a human handoff.

Official references

OpenAI Agents guide; OpenAI Agents SDK.

Last checked: 2026-11-16. Use the linked official documentation for current versions, interfaces, and safety boundaries.

Related practical cases

KnowledgeCase study: an auditable support-ticket triage agentKnowledgeCase study: a deployment-advice agent with human approvalKnowledgeCase study: an evidence package and human handoff after an agent failure

Further reading

KnowledgeAI Agents: From Core Concepts to ProductionKnowledgeStructured Outputs and Tool Contracts for Safe AgentsKnowledgeDesigning Reliable AI Automation Workflows
Product Hub Demo · V0.3