# Style OpenAI Function Calling / LangChain
MAX_STEPS = 6
def agent(goal, tools, controller, memory):
plan = planner_llm(goal, schema="json")
ctx = memory.short_tail() + memory.long_recall(goal)
for i, step in enumerate(plan["steps"][:MAX_STEPS], start=1):
controller.check_limits(step, i)
tool = tools.get(step["tool"])
args = controller.validate_inputs(tool, step["args"])
controller.pre_guardrails(tool, args)
obs = tool.run(**args) # call tool (typed)
controller.post_guardrails(tool, obs)
memory.log_tool(step, obs)
ctx = controller.compress(ctx + [obs])
if controller.success(goal, ctx): break
return final_llm_answer(goal, ctx)
# Déclaration d'outil typée
@tool(name="search_rag", input_schema=SearchSchema, pii="deny")
def search_rag(query:str, k:int=8) -> dict: ...
Guardrails critiques
- Stop si **non-progress** (répétitions de plan/outil).
- Ăchec outil â retry/backoff limitĂ© + fallback.
Production
- Observabilité complÚte + alerte temps réel.
- Canary release & budgets par feature.