Back to all articlesAI மற்றும் முகவர்கள்

Agent டூல் ஒப்பந்தங்களும் கட்டமைக்கப்பட்ட பிழைகளும் (Part 2)

A contract you can reason about

Typed contractvalidate args before execution
Classified errorsenum, not error strings
Idempotent retryno duplicated side effects
LLM retryfeed the error back as a message

A guarded tool call

Errors are data. The loop decides what to do with them.

  1. 01
    call dictname + args
  2. 02
    validate against schemareject before any side effect
  3. 03
    retry? classifiedtransient only, idempotent
  4. 04
    execute onceguarded, logged
  5. 05
    ToolResult(ok/error)typed and classified
  6. 06
    append to historyLLM sees the error

Part 1, terminates ஆகும் ஒரு லூப்புடனும், மாடல் சொல்வதெல்லாவற்றையும் நம்பும் ஒரு டூல் பதிவேட்டுடனும் முடிந்தது. அந்த நம்பிக்கையே அடுத்த பக். Part 1 இல் _search இன் முதல் வரி query = str(args.get("query", "")).lower() ஆக இருந்தது. மாடல் {"q": "agent loop"} அனுப்பினால் — {"query": "agent loop"} க்கு பதிலாக — எதுவும் error எழுப்பாது. query காலி சரமாகிறது, corpus தேடல் எதையும் பொருத்துவதில்லை, டூல் ["no matches"] தருகிறது. மாடல் இதை corpus காலி என்பதற்கான சான்றாகப் படித்து அதற்கேற்ப பதில் தருகிறது. error இல்லை, log வரி இல்லை, ஒரு JSON key இல் உள்ள தட்டெழுத்தை உண்மையான காலி முடிவிலிருந்து வேறுபடுத்தும் வழியும் இல்லை.

இந்தக் கட்டுரையை எழுதும்போது நான் சரியாக இதே ஒப்பீட்டை நடத்தினேன்: ஒரு உண்மையான மாடல் உண்மையில் உருவாக்கும் முப்பது தவறான argument payloadகள் — மாற்றப்பட்ட keys, பெரிய எழுத்துகளுடைய keys, integer இருக்க வேண்டிய இடத்தில் string, string க்கு பதிலாக list, null — Part 1 டூல் வழியாகவும் இங்கு நாம் உருவாக்கும் பதிப்பு வழியாகவும் செலுத்தப்பட்டன. Part 1 12 of 30 க்கு நம்பகமான தோற்றமுடைய காலி முடிவைத் தந்தது. ஒப்பந்தப் பதிப்பு 0 அமைதியான முடிவுகளைத் தந்தது: 27 வெளிப்படையான, வகைப்படுத்தப்பட்ட errors ஆகி schema குறிப்புடன் இருந்தன, 3 செல்லுபடியாகும் payloadகள் வெற்றி பெற்றன. அதே மாடல், அதே டூல்கள், வேறு failure தெரிவுநிலை.

இந்தப் பகுதி failure ஐத் தெரியும்படியும் மீண்டும் எடுக்கக்கூடியதாகவும் மாற்றுவதைப் பற்றியது. மாடலை கவனமாக இருக்கும்படி prompt கொடுப்பதால் அல்ல — ஒப்பந்தத்தைப் பூர்த்தி செய்யாத ஒரு call ஐ இயக்க மறுப்பதாலும், ஒவ்வொரு failure ஐயும் லூப் செயல்படக்கூடிய ஒரு வகைப்பட்ட மதிப்பாக மாற்றுவதாலும்.

நீங்கள் என்ன உருவாக்குவீர்கள்

Part 1 டூல் பதிவேட்டை நான்கு கூடுதல்களுடன் மூடும் ஒரு contracts.py தொகுதி:

  • validate_args(schema, args) — boolean க்கு பதிலாக {path, message} errors பட்டியலைத் தரும் ஒரு JSON Schema உட்கணத் திருத்தி, இதனால் மாடலுக்கு எந்த field தவறு என்பதை சரியாகக் கூறலாம்.
  • ErrorCode + ToolError — எட்டு failure வகைகளின் ஒரு மூடிய வகைப்பாடு, ஒவ்வொன்றோடும் ஒரு கேள்வி இணைக்கப்பட்டுள்ளது: இரண்டாவது முயற்சி வெற்றி பெறுமா?
  • RetryPolicy + IdempotencyStore — jitter உடன் வரம்பிடப்பட்ட exponential backoff, retry செய்யக்கூடிய codes க்கு மட்டும் பயன்படுத்தப்படும், மேலும் argument-hash keys மூலம் மீண்டும் இயக்கப்படும் side effect இருமுறை நடக்காது.
  • ToolExecutor — Tool.run இன் ஒரே அழைப்பாளர். இது சரிபார்க்கிறது, நகல்களை நீக்குகிறது, timeout இன் கீழ் இயக்குகிறது, வகைப்படுத்துகிறது, retry செய்கிறது.

AgentLoop Part 1 இல் உள்ள அதே வடிவத்தைத் தக்கவைக்கிறது. அதன் run method சுமார் ஆறு வரிகளில் மாறுகிறது: நேரடி tool.run(args) self.executor.execute(name, args) ஆகிறது, trace முயற்சிகளையும் error codes ஐயும் பதிவு செய்கிறது. மற்ற அனைத்தும் — Message, ToolResult, ScriptedLLM, முடிவு வடிவங்கள் — இணக்கமாக இருக்கின்றன, ஏனெனில் Part 3, Part 4 ஆகியவர் இந்தக் கோப்பை மாற்றாமல் நீட்டிக்கின்றனர்.

முன்நிபந்தனைகள்

  • Python 3.10 அல்லது புதியது. நிலையான நூலகம் மட்டும்: concurrent.futures, hashlib, json, random, time, urllib.
  • Part 1 கோப்பு, அல்லது குறைந்தபட்சம் அதன் நான்கு வகைகள்: Message, ToolResult, Tool, AgentLoop. அதைத் தவிர்த்திருந்தால், கீழே உள்ள தொகுதி அவற்றை இணக்கமாக மீண்டும் வரையறுக்கிறது.
  • ஒரு முனையம். இங்குள்ள ஒவ்வொரு சோதனையும் இணையத் தொடர்பின்றி ஒரு வினாடிக்குள் இயங்கும்.

ஒரு நோக்கமுடைய தவிர்ப்பு: validate_args JSON Schema இன் ஒரு உட்கணத்தை ஆதரிக்கிறது — type, properties, required, additionalProperties, items, enum, minLength, maxLength, minimum, maximum. இந்த உட்கணம் நடைமுறையில் உண்மையான டூல் schemas பயன்படுத்துவதை உள்ளடக்குகிறது. இது $ref, oneOf, pattern ஐ ஆதரிக்காது; அவ்வாறு கூறுவது இல்லை என்பதைக் கூறுவதைவிட மோசம். உங்களுக்கு அவை தேவைப்பட்டால், jsonschema அல்லது Pydantic ஐ நாடுவதே சரியான தீர்மானம்; சுற்றியுள்ள executor வடிவமைப்பு மாறாது.

ஒப்பந்தம் உண்மையில் எங்கு உடைகிறது

மாடலுக்கும் டூலுக்கும் இடையே நடக்கும் தவறுகளில் பெரும்பாலானவை மூன்று failure வகைகளால் ஏற்படுகின்றன, அவை வேறு விதமாக கையாளப்பட வேண்டும்.

தவறான key, நம்பகமான நோக்கம். {"q": ...} என்பது query தேவைப்படும் ஒரு schema க்கு எதிராக அனுப்பப்படுகிறது. Python இன் dict.get இயல்புநிலை அமைதியாக "" கொடுக்கிறது. இதுதான் அபாயகரமானது, ஏனெனில் டூல் வெற்றி பெறுகிறது, பதில் தவறாகிறது.

சரியான key, தவறான type. {"limit": "3"} [v for ...][:limit] வரை சென்று TypeError: slice indices must be integers ஐ எழுப்புகிறது. Part 1 இல் அந்த விதிவிலக்கு AgentLoop.run ஆல் பிடிக்கப்பட்டு ToolResult(ok=False) ஆக மாற்றப்படுகிறது — ஆனால் செய்தி TypeError: slice indices must be integers or None or have an __index__ method ஆகும், இது எந்த argument ஐ சரிசெய்ய வேண்டும் என்பதை மாடலுக்குச் சொல்லாது.

சரியான call, தற்காலிக failure. search backend இலிருந்து 429, socket timeout, index இலிருந்து 503. retry செய்வது சரி. ஆனால் response இழந்ததால் save_note call ஐ மீண்டும் செய்தால் write நகலாகும்.

நான் பயன்படுத்திய சோதனை இதோ — 12-of-30 எண்ணை நம்பாமல் நீங்களே மீண்டும் உருவாக்கலாம்:

import json
from contracts import ToolExecutor, ToolResult, build_tools
def search_v1(args: dict) -> ToolResult:
query = str(args.get("query", "")).lower()
corpus = {
"agent loop": "An agent loop repeats: observe, decide, act, observe.",
"token budget": "Context windows are finite; budget them explicitly.",
"stop condition": "A step limit is a stop condition, not a strategy.",
"retry": "Retry only failures that are transient; never retry a 400.",
}
hits = [v for key, v in corpus.items() if key in query]
return ToolResult(ok=True, data=json.dumps(hits or ["no matches"]))
PAYLOADS = [
{"query": "agent loop"}, {"q": "agent loop"}, {"Query": "agent loop"},
{"query": "agent loop", "top_k": 3}, {"query": ["agent loop"]},
{"query": "agent loop", "limit": "3"}, {"query": "agent loop", "limit": 0},
{"query": ""}, {"query": "agent loop", "limit": True}, {"query": None},
]
def probe() -> None:
cases = (PAYLOADS * 3)[:30]
executor = ToolExecutor({t.name: t for t in build_tools()}, sleep=lambda d: None)
silent_v1 = silent_v2 = explicit_v2 = 0
for args in cases:
old = search_v1(args)
new = executor.execute("search", args)
if old.ok and json.loads(old.data) == ["no matches"]:
silent_v1 += 1
if not new.ok:
explicit_v2 += 1
elif json.loads(new.data) == ["no matches"]:
silent_v2 += 1
print("n=%d v1_silent=%d v2_explicit=%d v2_silent=%d"
% (len(cases), silent_v1, explicit_v2, silent_v2))
if __name__ == "__main__":
probe()

வெளியீடு: n=30 v1_silent=12 v2_explicit=27 v2_silent=0. மீதமுள்ள மூன்று வெற்றிகள் செல்லுபடியாகும் payload {"query": "agent loop"}, மூன்று முறை திரும்பக் கொண்டுவரப்பட்டது. அமைதியான தவறான பதில் ஒரு பிழையைவிட மோசம், ஏனெனில் அதை சரியான எதிர்மறை முடிவிலிருந்து வேறுபடுத்த முடியாது, மேலும் அது எந்த எதிர்ப்புமின்றி இறுதி பதிலில் பரவுகிறது.

காரணம் கூறக்கூடிய ஒரு திருத்தி

திருத்தி boolean அல்ல, கட்டமைக்கப்பட்ட errors தருகிறது, ஏனெனில் error உரையே மாடல் தனது அடுத்த திருப்பத்தில் படிக்கும் சரிசெய்தல் வழிமுறை. boolean உங்களை ஒரு செய்தியை கண்டுபிடிக்க வற்புறுத்துகிறது; ஒரு path உம் காரணமும் அதை இயந்திரமாக உருவாக்க அனுமதிக்கிறது.

from __future__ import annotations
from dataclasses import dataclass, replace
from typing import Any, Callable
import json
@dataclass
class Message:
role: str # "system" | "user" | "assistant" | "tool"
content: str
name: str | None = None # tool name, required when role == "tool"
@dataclass
class ToolResult:
ok: bool
data: str
error: str | None = None
error_code: str | None = None
attempts: int = 1
from_cache: bool = False
def to_message(self, name: str) -> Message:
if self.ok:
payload = self.data
else:
payload = "ERROR[%s]: %s" % (self.error_code or "unknown", self.error or "")
return Message(role="tool", content=payload, name=name)
def validate_args(schema: dict, args: Any) -> list[dict]:
"""Validate a JSON Schema subset. Returns [] or a list of {path, message}."""
errors: list[dict] = []
def walk(sch: dict, value: Any, path: str) -> None:
t = sch.get("type")
if t == "object":
if not isinstance(value, dict):
errors.append({"path": path or "/", "message": "expected object"})
return
props = sch.get("properties", {})
for req in sch.get("required", []):
if req not in value:
errors.append({"path": path + "/" + req, "message": "missing required field"})
if sch.get("additionalProperties") is False:
for key in value:
if key not in props:
errors.append({"path": path + "/" + str(key), "message": "unexpected field"})
for key, sub in props.items():
if key in value:
walk(sub, value[key], path + "/" + key)
return
if t == "array":
if not isinstance(value, list):
errors.append({"path": path, "message": "expected array"})
return
item_schema = sch.get("items", {})
for i, item in enumerate(value):
walk(item_schema, item, path + "/" + str(i))
return
if t == "string":
if not isinstance(value, str):
errors.append({"path": path, "message": "expected string"})
return
elif t == "integer":
if isinstance(value, bool) or not isinstance(value, int):
errors.append({"path": path, "message": "expected integer"})
return
elif t == "number":
if isinstance(value, bool) or not isinstance(value, (int, float)):
errors.append({"path": path, "message": "expected number"})
return
elif t == "boolean":
if not isinstance(value, bool):
errors.append({"path": path, "message": "expected boolean"})
return
if "enum" in sch and value not in sch["enum"]:
errors.append({"path": path, "message": "must be one of " + repr(sch["enum"])})
if "minLength" in sch and isinstance(value, str) and len(value) < sch["minLength"]:
errors.append({"path": path, "message": "shorter than minLength %d" % sch["minLength"]})
if "maxLength" in sch and isinstance(value, str) and len(value) > sch["maxLength"]:
errors.append({"path": path, "message": "longer than maxLength %d" % sch["maxLength"]})
if "minimum" in sch and isinstance(value, (int, float)) and not isinstance(value, bool):
if value < sch["minimum"]:
errors.append({"path": path, "message": "below minimum %s" % sch["minimum"]})
if "maximum" in sch and isinstance(value, (int, float)) and not isinstance(value, bool):
if value > sch["maximum"]:
errors.append({"path": path, "message": "above maximum %s" % sch["maximum"]})
walk(schema, args, "")
return errors

அந்தக் குறியீட்டில் உள்ள இரண்டு விவரங்கள் அலங்காரம் அல்ல. முதலாவது, isinstance(value, bool) பாதுகாப்பு integer மற்றும் number இல் உள்ளது: Python இல் True என்பது 1 மதிப்புடைய ஒரு int, எனவே {"limit": true} integer சோதனையைகடந்து limit=1 ஆகும். இரண்டாவது, திருத்தி முதல் error இல் நிற்பதில்லை — அது அனைத்தையும் சேகரித்து, முதல் மூன்றைப் புகாரளிக்கிறது. இரண்டு தவறான field களை அனுப்பிய மாடல் இரண்டு முறையல்ல, ஒரே round trip இல் இரண்டையும் அறிய வேண்டும்.

error கள் ஒரு சரிசெய்தல் இலக்குடன் வந்தால் மட்டுமே பயனுள்ளவை. describe_schema சேர்ப்பது அதுதான்: அதே schema பொருளிலிருந்து உருவான ஒரு சுருக்கமான கையொப்பம்.

def describe_schema(schema: dict) -> str:
"""Compact, model-readable signature: query:string!, limit:integer."""
parts = []
required = set(schema.get("required", []))
for name, sub in schema.get("properties", {}).items():
piece = name + ":" + str(sub.get("type", "any"))
if name in required:
piece += "!"
if "enum" in sub:
piece += "=" + "|".join(str(v) for v in sub["enum"])
parts.append(piece)
return "{" + ", ".join(parts) + "}"
def format_errors(errors: list[dict], limit: int = 3) -> str:
shown = ["%s %s" % (e["path"] or "/", e["message"]) for e in errors[:limit]]
if len(errors) > limit:
shown.append("(+%d more)" % (len(errors) - limit))
return "; ".join(shown)

{"q": ...} நிலைக்கான விளைவு டூல் செய்தி ERROR[invalid_arguments]: /q unexpected field; /query missing required field. expected {query:string!, limit:integer}. expected க்குப் பிறகுள்ள பகுதி schema இலிருந்து உருவாக்கப்படுகிறது, எனவே நீங்கள் schema ஐத் திருத்தும்போது அது மாறிவிட முடியாது. இந்தப் பண்பு சொற்களேற்றத்தைவிட முக்கியமானது: கையால் எழுதிய சரிசெய்தல் குறிப்புகள் பழமையாகின்றன, உருவாக்கப்பட்டவை அல்ல.

இதன் விலை என்னவென்று கவனிக்கவும். additionalProperties: False கடுமையானது — பாதகமற்ற metadata field ஐச் சேர்க்கும் ஒரு வழங்குநர் சரிபார்ப்பில் தோல்வியடைவார். அதுதான் நோக்கம்: எதிர்பாராத field என்பது மாடல் ஒரு parameter ஐ கற்பனை செய்ததா அல்லது உங்கள் schema குறியீட்டுக்குப் பின்தங்கியதா என்பதாகும்; இரண்டும் அமைதியான **kwargs தோள்புரட்டலைவிட உயர்ந்த failure க்கு தகுதியானவை.

சரங்களுக்குப் பதிலாக வகைப்படுத்தப்பட்ட errors

ஒரு சர error ஐ பதிவு செய்யலாம். ஒரு வகைப்படுத்தப்பட்ட error ஐப் பற்றி முடிவெடுக்க முடியும். கீழேயுள்ள வகைப்பாடு நோக்கமாகவே சிறியது; எட்டு codes டூல்பயன்படுத்தும் agents இல் நான் உண்மையில் கண்ட failure களை உள்ளடக்குகின்றன, ஒவ்வொன்றும் ஒரு செயலோடு பொருந்துகிறது.

from enum import Enum
class ErrorCode(str, Enum):
INVALID_ARGUMENTS = "invalid_arguments"
UNKNOWN_TOOL = "unknown_tool"
NOT_FOUND = "not_found"
RATE_LIMITED = "rate_limited"
TIMEOUT = "timeout"
UPSTREAM = "upstream_error"
PERMISSION = "permission_denied"
INTERNAL = "internal_error"
class ToolError(Exception):
"""Raise inside a tool to report a classified, non-crashing failure."""
def __init__(self, message: str, code: ErrorCode = ErrorCode.INTERNAL,
retry_after: float | None = None):
super().__init__(message)
self.code = code
self.retry_after = retry_after

வகைப்பாட்டு விதி ஒரு கேள்விதான்: மாற்றங்கள் எதுவுமின்றி அதே இரண்டாவது முயற்சி நம்பத்தகுந்தவாறு வெற்றி பெறுமா? rate_limited, timeout, upstream_error ஆம் என்கின்றன. invalid_arguments, unknown_tool, not_found, permission_denied, internal_error இல்லை என்கின்றன — முதல் மூன்றுக்கு வேறு call தேவை, கடைசி இரண்டுக்கு ஒரு மனிதர் தேவை. அந்தக் கேள்விதான் எல்லாவற்றையும் retry செய்யாததற்கான முழு காரணம்: ஒவ்வொரு வீணான retry-யும் max_steps இலிருந்து ஒரு படியைச் செலவழிக்கிறது, ஒரு டூல் call க்கு மூன்று முயற்சிகளில் ஐந்து-டூல் பட்ஜெட்டு இரண்டாகச் சுருங்குகிறது.

Tool மூன்று ஒப்பந்த field களைப் பெறுகிறது, விளக்கம் இப்போது Part 1 இல் இல்லாத வகையில் சுமை தாங்குவதாக உள்ளது:

@dataclass
class Tool:
name: str
description: str
parameters: dict[str, Any] # JSON Schema
_fn: Callable[[dict], ToolResult]
side_effect: bool = False # True -> executed at most once per idempotency key
timeout_s: float = 5.0
def spec(self) -> dict:
return {
"type": "function",
"function": {
"name": self.name,
"description": self.description,
"parameters": self.parameters,
},
}
def run(self, args: dict) -> ToolResult:
return self._fn(args)

மூன்று டூல்களும் நேர்மையான schemas ஐ அறிவிக்கின்றன, முன்பு அமைதியாகத் தோல்வியடைந்த இரண்டும் இப்போது சத்தமாகத் தோல்வியடைகின்றன. தனது backend கீழே இருக்கும்போது _search, காலி பட்டியலைத் தருவதற்குப் பதிலாக வகைப்படுத்தப்பட்ட ToolError ஐ எழுப்புகிறது, ஏனெனில் காலி பட்டியலும் timeout உம் மாடலுக்கு எதிர்ப்பொருள் கொண்டவை:

def _search(args: dict) -> ToolResult:
query = str(args.get("query", "")).strip().lower()
limit = int(args.get("limit", 3))
corpus = {
"agent loop": "An agent loop repeats: observe, decide, act, observe.",
"token budget": "Context windows are finite; budget them explicitly.",
"stop condition": "A step limit is a stop condition, not a strategy.",
"retry": "Retry only failures that are transient; never retry a 400.",
}
hits = [v for key, v in corpus.items() if key in query][:limit]
if "timeout" in query:
raise ToolError("upstream search index timed out", ErrorCode.TIMEOUT)
return ToolResult(ok=True, data=json.dumps(hits or ["no matches"]))
def _calculate(args: dict) -> ToolResult:
expr = str(args.get("expression", ""))
allowed = set("0123456789+-*/(). ")
if not expr or not set(expr) <= allowed:
return ToolResult(ok=False, data="", error="illegal characters in expression",
error_code=ErrorCode.INVALID_ARGUMENTS)
try:
value = eval(expr, {"__builtins__": {}}, {})
except Exception as exc:
return ToolResult(ok=False, data="", error=type(exc).__name__ + ": " + str(exc),
error_code=ErrorCode.INVALID_ARGUMENTS)
return ToolResult(ok=True, data=str(value))
def _save_note(args: dict) -> ToolResult:
import os
os.makedirs("notes", exist_ok=True)
path = "notes/" + str(args.get("name", "note")) + ".txt"
with open(path, "w", encoding="utf-8") as f:
f.write(str(args.get("body", "")))
return ToolResult(ok=True, data="saved " + path)
def build_tools() -> list[Tool]:
return [
Tool(
name="search",
description="Search the local research corpus. Returns a JSON list of matching passages.",
parameters={
"type": "object",
"properties": {
"query": {"type": "string", "minLength": 2, "maxLength": 200},
"limit": {"type": "integer", "minimum": 1, "maximum": 10},
},
"required": ["query"],
"additionalProperties": False,
},
_fn=_search,
),
Tool(
name="calculate",
description="Evaluate a pure arithmetic expression. No variables, no functions.",
parameters={
"type": "object",
"properties": {"expression": {"type": "string", "minLength": 1, "maxLength": 100}},
"required": ["expression"],
"additionalProperties": False,
},
_fn=_calculate,
),
Tool(
name="save_note",
description="Persist a note to disk. Non-idempotent: each call writes a file.",
parameters={
"type": "object",
"properties": {
"name": {"type": "string", "minLength": 1, "maxLength": 40},
"body": {"type": "string", "maxLength": 4000},
},
"required": ["name", "body"],
"additionalProperties": False,
},
_fn=_save_note,
side_effect=True,
timeout_s=2.0,
),
]

minLength: 2 ஐ query இல் பயன்படுத்துவது அலங்காரம் அல்ல. பன்னிரண்டு அமைதியான தோல்விகளை உருவாக்கிய காலி-query நிலைக்கு எதிரான மலிவான பாதுகாப்பு இதுவே: இப்போது ஒரு காலி சரம் டூல் உடல் பார்ப்பதற்கு முன்பே ஒப்பந்தத்தால் நிராகரிக்கப்படுகிறது.

பக்க விளைவை நகலாக்க முடியாத retry

Backoff என்பது எளிதான பாதி. கடினமான பாதி ஒரு write ஐ மீண்டும் செய்தால் இரண்டு முறை write ஆகலாம் என்பது: கோரிக்கை வெற்றி பெற்றது, response இழக்கப்பட்டது, உங்கள் retry இரண்டாவது note ஐ உருவாக்கியது. தீர்வு டூல் பெயரிலிருந்தும் நிலையான arguments இலிருந்தும் உருவான ஒரு key, மேலும் எந்த call க்கள் குறுக்கு முடிவை மீண்டும் பயன்படுத்தலாம் என்பதற்கான ஒரு விதி.

import hashlib
import random
import time
@dataclass
class RetryPolicy:
max_attempts: int = 3
base_delay: float = 0.05
max_delay: float = 2.0
jitter: float = 0.25
retryable: frozenset = frozenset(
{ErrorCode.RATE_LIMITED, ErrorCode.TIMEOUT, ErrorCode.UPSTREAM}
)
def is_retryable(self, code: str | None) -> bool:
return code in {c.value for c in self.retryable}
def delay_for(self, attempt: int, rnd: random.Random) -> float:
raw = min(self.max_delay, self.base_delay * (2 ** (attempt - 1)))
return raw * (1.0 + rnd.uniform(-self.jitter, self.jitter))
class IdempotencyStore:
"""Remembers completed calls by (tool, canonical args) hash."""
def __init__(self) -> None:
self._done: dict[str, ToolResult] = {}
@staticmethod
def key(name: str, args: dict) -> str:
blob = json.dumps(args, sort_keys=True, separators=(",", ":"))
return name + ":" + hashlib.sha256(blob.encode("utf-8")).hexdigest()[:16]
def get(self, key: str) -> ToolResult | None:
return self._done.get(key)
def put(self, key: str, result: ToolResult) -> None:
self._done[key] = result

sort_keys=True தான் key ஐ நிலையானதாக்குகிறது: {"a": 1, "b": 2} மற்றும் {"b": 2, "a": 1} ஒரே call ஆகும், அவை ஒரே key ஐ உருவாக்க வேண்டும், இல்லையெனில் பாதுகாப்பு கசிகிறது. Jitter ஒரு ஆடம்பரமல்ல — இல்லையெனில் ஒரே 429 ஐத் தாக்கும் பத்து workers ஒரே சமயத்தில் retry செய்து மீண்டும் ஒன்றாகத் தாக்குகின்றன; ±25% அவர்களைப் பரப்புகிறது.

executor என்பது நான்கு கவலைகளும் இணையும் இடம், அதன் வரிசையே வடிவமைப்பு: முதலில் சரிபார், பிறகு நகல்கள் நீக்கு, பிறகு இயக்கு, பிறகு வகைப்படுத்து, பிறகு retry. நகல் நீக்கத்திற்கு முன் சரிபார்ப்பு என்பது தவறான call ஒருபோதும் key ஐ ஆக்கிரமிக்காது என்பதாகும்.

import concurrent.futures
class ToolExecutor:
"""Validate -> de-duplicate -> execute -> classify -> retry. The only caller of Tool.run."""
def __init__(
self,
tools: dict[str, Tool],
policy: RetryPolicy | None = None,
store: IdempotencyStore | None = None,
sleep: Callable[[float], None] = time.sleep,
rnd: random.Random | None = None,
) -> None:
self.tools = tools
self.policy = policy or RetryPolicy()
self.store = store or IdempotencyStore()
self.sleep = sleep
self.rnd = rnd or random.Random(0)
def execute(self, name: str, args: dict) -> ToolResult:
tool = self.tools.get(name)
if tool is None:
return ToolResult(ok=False, data="", error="unknown tool: " + name,
error_code=ErrorCode.UNKNOWN_TOOL.value)
errors = validate_args(tool.parameters, args)
if errors:
hint = "expected " + describe_schema(tool.parameters)
return ToolResult(ok=False, data="", error=format_errors(errors) + ". " + hint,
error_code=ErrorCode.INVALID_ARGUMENTS.value)
key = self.store.key(name, args)
cached = self.store.get(key)
if cached is not None and (tool.side_effect or not cached.ok):
return replace(cached, from_cache=True, attempts=0)
attempt = 0
while True:
attempt += 1
result = self._attempt(tool, args)
result.attempts = attempt
if result.ok:
self.store.put(key, result)
return result
if not self.policy.is_retryable(result.error_code):
# Negative cache: an identical call that failed permanently will fail
# again. Caching it stops a looping model from re-burning the quota.
self.store.put(key, result)
return result
if attempt >= self.policy.max_attempts:
return result
self.sleep(self.policy.delay_for(attempt, self.rnd))
def _attempt(self, tool: Tool, args: dict) -> ToolResult:
pool = concurrent.futures.ThreadPoolExecutor(max_workers=1)
try:
future = pool.submit(tool.run, args)
return future.result(timeout=tool.timeout_s)
except concurrent.futures.TimeoutError:
return ToolResult(ok=False, data="", error="tool exceeded %.1fs" % tool.timeout_s,
error_code=ErrorCode.TIMEOUT.value)
except ToolError as exc:
return ToolResult(ok=False, data="", error=str(exc), error_code=exc.code.value)
except Exception as exc:
return ToolResult(ok=False, data="", error=type(exc).__name__ + ": " + str(exc),
error_code=ErrorCode.INTERNAL.value)
finally:
pool.shutdown(wait=False)

பெயரிடத்தக்க இரு நுட்பங்கள். குறுக்கு-மறுபயன்பாட்டு நிபந்தனை tool.side_effect or not cached.ok: ஒரு write பதுக்கப்பட்ட வெற்றியை மீண்டும் பயன்படுத்தலாம் (இது at-most-once), எந்த call ஆனாலும் பதுக்கப்பட்ட failure ஐ மீண்டும் பயன்படுத்தலாம் (இது negative cache ஆகும், அது சிக்கியுள்ள மாடல் அதே உடைந்த call இல் மீண்டும் quota எரிப்பதைத் தடுக்கிறது). படிப்பு-மட்டும் வெற்றிகள் நோக்கமாகப் பதுக்கப்படாது, ஏனெனில் இரண்டு நிமிடங்களுக்கு முன் எதையும் தராத search இப்போது ஏதாவது தரலாம், பழைய வாசிப்புகள் தவறான பதிலின் சொந்த வகையாகும்.

இரண்டாவது நுட்பம் timeout. future.result(timeout=...) என்பது நீங்கள் எவ்வளவு நேரம் காத்திருக்கிறீர்கள் என்பதை மட்டுமே வரம்பிடுகிறது, டூல் எவ்வளவு நேரம் இயங்குகிறது என்பதை அல்ல — Python ஒரு thread ஐக் கொல்ல முடியாது. timeout ஐப் புறக்கணிக்கும் டூல் பின்னணியில் CPU எரித்துக்கொண்டே இருக்கும், லூப் முன்னேறிவிடும். இது ஒரு நேர்மையான வரம்பு, Part 11 இது process-level sandbox ஆல் மாற்றப்படுவதற்கு இதுவே காரணம். timeout_s ஐ பாதுகாப்பு எல்லையாக அல்ல, latency பட்ஜெட்டாகப் படிக்கவும்.

லூப்புடன் இணைத்தல், நாம் தவிர்த்த LLM retry உடன்

Part 1 ஒரு இடைவெளியை விட்டிருந்தது, அதை நான் வெளிப்படையாகக் குறித்தேன்: AgentLoop.run tool.run ஐப் பாதுகாத்தது ஆனால் llm.complete ஐ அல்ல, எனவே மாடல் endpoint இலிருந்து ஒரு 503 முழு run ஐ முடித்துவிடும். அதே கொள்கை HTTP status codes இல் பயன்படுத்தப்பட்டு அதை மூடுகிறது.

import urllib.error
class LLMClient:
def complete(self, messages: list[Message], tools: list[dict]) -> dict:
raise NotImplementedError
class ScriptedLLM(LLMClient):
"""Replays a fixed list of decisions. Used for offline tests and demos."""
def __init__(self, script: list[dict]):
self.script = list(script)
self.calls: list[list[Message]] = []
def complete(self, messages: list[Message], tools: list[dict]) -> dict:
self.calls.append(list(messages))
if not self.script:
return {"type": "final", "content": "no scripted decision left"}
return self.script.pop(0)
def classify_http_status(status: int) -> ErrorCode:
if status == 429:
return ErrorCode.RATE_LIMITED
if status in (408, 504):
return ErrorCode.TIMEOUT
if 500 <= status < 600:
return ErrorCode.UPSTREAM
if status in (401, 403):
return ErrorCode.PERMISSION
return ErrorCode.INVALID_ARGUMENTS
class RetryingLLM(LLMClient):
"""Wraps any client; retries only the codes that a second attempt can fix."""
def __init__(self, inner: LLMClient, policy: RetryPolicy | None = None,
sleep: Callable[[float], None] = time.sleep,
rnd: random.Random | None = None) -> None:
self.inner = inner
self.policy = policy or RetryPolicy()
self.sleep = sleep
self.rnd = rnd or random.Random(7)
self.attempts: list[int] = []
def complete(self, messages: list[Message], tools: list[dict]) -> dict:
attempt = 0
while True:
attempt += 1
try:
decision = self.inner.complete(messages, tools)
self.attempts.append(attempt)
return decision
except urllib.error.HTTPError as exc:
code = classify_http_status(exc.code)
if not self.policy.is_retryable(code.value) or attempt >= self.policy.max_attempts:
self.attempts.append(attempt)
raise
self.sleep(self.policy.delay_for(attempt, self.rnd))

401 முதல் முயற்சியில் எழுப்பப்படுகிறது, மூன்றாவதில் அல்ல: தவறான key தவறாகவே இருக்கும், மூன்று முயற்சிகள் தோல்விக்கு முன் உங்கள் latency ஐ மட்டும் மும்மடங்காக்கும். 400 அதே காரணத்தால் invalid_arguments ஆக வகைப்படுத்தப்படுகிறது — உங்கள் payload தவறு, அதை மீண்டும் அனுப்புவது அர்த்தமற்றது.

லூப் மாற்றம் சிறியது, மதிப்பு trace இல் தெரிகிறது:

SYSTEM = (
"You are a research agent. Use the provided tools to gather evidence, "
"then answer with a final decision. Do not claim facts you did not retrieve. "
"If a tool returns ERROR[invalid_arguments], fix the arguments using the schema shown."
)
class AgentLoop:
def __init__(self, llm: LLMClient, tools: list[Tool], max_steps: int = 8,
executor: ToolExecutor | None = None):
self.llm = llm
self.tools = {t.name: t for t in tools}
self.specs = [t.spec() for t in tools]
self.max_steps = max_steps
self.trace: list[dict] = []
self.executor = executor or ToolExecutor(self.tools)
def run(self, goal: str) -> str:
history = [
Message(role="system", content=SYSTEM),
Message(role="user", content=goal),
]
for step in range(self.max_steps):
decision = self.llm.complete(history, self.specs)
kind = decision.get("type")
record = {"step": step, "decision": decision}
self.trace.append(record)
if kind == "final":
return str(decision.get("content", ""))
if kind != "tool":
return "aborted: malformed decision " + repr(decision)
name = str(decision.get("name", ""))
args = decision.get("arguments", {})
if not isinstance(args, dict):
args = {}
result = self.executor.execute(name, args)
record.update({"tool": name, "ok": result.ok, "attempts": result.attempts,
"error_code": result.error_code, "from_cache": result.from_cache})
history.append(result.to_message(name))
return "aborted: step limit reached"

SYSTEM prompt இப்போது error வடிவத்தைப் பெயரிடுகிறது. இது prompt-engineering மந்திரவாதம் அல்ல: மாடலுக்கு தோல்வியில் அது காணும் சரியான சரமும் அதனுடன் செய்வதென்னவென்பதும் கூறப்படுகிறது. இதன் விலை ஒரு வாக்கியம், சரிபார்ப்பு error க்குப் பிறகு கைகால்கள் படைப்பதில் செலவழிக்கப்படும் திருப்பங்களை அளவிடக்கூடிய அளவு குறைக்கிறது, ஏனெனில் சரிசெய்தல் இலக்கு error இலேயே உள்ளது.

இயக்கவும், trace ஒரு பதிவேடுக்குப் பதிலாக ஒரு நோயறிதலைப்போல படிக்கப்படும்:

def demo() -> None:
script = [
{"type": "tool", "name": "search", "arguments": {"q": "agent loop"}},
{"type": "tool", "name": "search", "arguments": {"query": "agent loop", "limit": 1}},
{"type": "tool", "name": "save_note", "arguments": {"name": "loop", "body": "observe decide act"}},
{"type": "tool", "name": "save_note", "arguments": {"name": "loop", "body": "observe decide act"}},
{"type": "final", "content": "The agent loop repeats observe, decide, act."},
]
agent = AgentLoop(ScriptedLLM(script), build_tools(), max_steps=8)
print("ANSWER:", agent.run("Explain the agent loop."))
for rec in agent.trace:
if "tool" in rec:
print(rec["step"], rec["tool"], "ok=%s" % rec["ok"],
"attempts=%d" % rec["attempts"], rec["error_code"], "cached=%s" % rec["from_cache"])
if __name__ == "__main__":
demo()
ANSWER: The agent loop repeats observe, decide, act.
0 search ok=False attempts=1 invalid_arguments cached=False
1 search ok=True attempts=1 None cached=False
2 save_note ok=True attempts=1 None cached=False
3 save_note ok=True attempts=0 None cached=True

படி 0 ஒப்பந்தம் call ஐ நிராகரிப்பதைக் காட்டுகிறது. படி 1 மாடல் அடுத்த திருப்பத்தில் மீண்டதைக் காட்டுகிறது — அந்த மீட்பு error செய்தியால் ஏற்பட்டது, குறிப்பு schema இலிருந்து உருவாக்கப்படுவதற்கு இதுவே காரணம். படி 3 attempts=0 உடன் ஒரு அதே write கோரிக்கை பதுக்கப்பட்டதிலிருந்து வழங்கப்படுவதைக் காட்டுகிறது: இரண்டாவது கோப்பு இல்லை, இரண்டாவது network call இல்லை.

failure முறைகளும் அவற்றைக் கையாளும் விதமும்

Failure உண்மையில் என்ன நடக்கிறது இங்கு கையாளுதல் இன்னும் என்ன உடைகிறது
மாடல் மாற்றப்பட்ட key அனுப்புகிறது additionalProperties: False அதைக் குறித்துக் காட்டுகிறது, required காணாமல் போன field பெயரைச் சொல்கிறது schema குறிப்புடன் வெளிப்படையான invalid_arguments; மாடல் அடுத்த திருப்பத்தில் சரிசெய்கிறது குறிப்பைப் புறக்கணிக்கும் மாடல் அனைத்து படிகளையும் எரிக்கிறது
மாடல் integer க்கு true அனுப்புகிறது Python bool ஐ int ஆக நடத்துகிறது, எனவே எளிய சோதனை தேர்ச்சி பெறுகிறது isinstance(value, bool) பாதுகாப்பு அதை நிராகரிக்கிறது எதுவுமில்லை — இது மூடப்பட்டது
டூல் தொங்குகிறது future timeout ஆனபின் thread இயங்கிக்கொண்டே இருக்கிறது timeout_s timeout தருகிறது, பட்ஜெட்டு வரை retry Process-level CPU எரிப்பு; kill switch இல்லை (Part 11)
429 பெருக்கம் ஒவ்வொரு முயற்சியும் வரம்பை மீண்டும் தாக்குகிறது வரம்பிட்ட முயற்சிகள், exponential backoff, ±25% jitter cross-process rate limiter இல்லை (Part 12)
write இல் response இழப்பு retry கோப்பை நகலாக்கும் Idempotency key + side_effect=True பதுக்கப்பட்ட வெற்றியைத் தருகிறது In-memory store செயல்முறையுடன் இறக்கிறது (Part 8)
அதே உடைந்த call தொடர்ச்சியாக மாடல் ஒரு error இல் சுழல்கிறது Negative cache மீண்டும் இயக்குவதை நிறுத்துகிறது லூப் இன்னும் படிகள் செலவழிக்கிறது; repeat detector தேவை
schema உம் குறியீடும் வேறுபடுதல் சரிபார்ப்பு டூல் வேண்டும் field ஐ நிராகரிக்கிறது describe_schema schema இலிருந்து குறிப்பை மீண்டும் உருவாக்குகிறது யாரும் தானியங்கியாக வேறுபாட்டைக் கண்டறிய மாட்டார்

கடைசி வரிதான் என்னைக் கடித்தது. describe_schema சரியாக இருப்பதற்குக் காரணம் அதுவும் validate_args உம் ஒரே dict ஐப் படிப்பதே. நீங்கள் prompt இல் schema இன் இரண்டாவது பிரதியைக் கையால் எழுதினால், இரண்டும் ஒரு மாதத்துள் வேறுபடும் — தோல்வி மாடல் பிழையாகத் தோன்றும், பராமரிப்புப் பிழையாக அல்ல.

வர்த்தக இணக்கங்கள்

முடிவு மாற்று ஏன் இதைத் தேர்வு செய்தோம் விலை
கையால் செய்த உட்கணத் திருத்தி jsonschema அல்லது Pydantic சுழிய சார்புகள், ~120 வரிகள், மாடலுக்கான errors $ref/oneOf/pattern இல்லை; நீங்களே பராமரிக்க வேண்டும்
errors ஐ ToolResult மதிப்புகளாக லூப் வழியாக விதிவிலக்குகள் எழுப்பு மாடல் படித்து சரிசெய்ய முடியும்; லூப் எளிமையாக இருக்கும் அழைப்பாளர்கள் எல்லா இடங்களிலும் ok சோதிக்க வேண்டும்
additionalProperties: False கூடுதல் field களை அனுமதி கற்பனை செய்யப்பட்ட parameters உடனடியாகப் பிடிபடும் வழங்குநர் metadata சேர்க்கும்போது உடையும்
In-memory idempotency keys Redis அல்லது SQLite ஒரு dict, infra இல்லை, சோதிக்கக்கூடியது workers இடையே பகிரப்படாது; மறுதொடக்கத்தில் இழக்கப்படும்
Thread timeout Process sandbox 10 வரிகள், IPC இல்லை கட்டுப்பாடற்ற டூலைக் கொல்ல முடியாது (Part 11)
3 codes மட்டும் retry அனைத்தையும் ஒருமுறை retry படி பட்ஜெட்டைப் பாதுகாக்கிறது நிலையற்ற not_found ஒருபோதும் retry ஆகாது
எதிர்மறை முடிவுகளை பதுக்கு எப்போதும் மீண்டும் இயக்கு சுழலும் மாடலின் retry பெருக்கத்தை நிறுத்துகிறது நிரந்தரமானதாகத் தவறாக வகைப்படுத்தப்பட்ட தற்காலிக failure பதுக்கப்படும்

திருத்தித் தேர்வு அதிக ஆய்வுக்கு தகுதியானது. Pydantic உங்களுக்கு coercion, nested models, சிறந்த error செய்திகளை இலவசமாகத் தரும் — ஒரு சார்பு, மெதுவான import, மற்றும் எப்படியும் மாடல்-படிக்கக்கூடிய உரையாக மாற்ற வேண்டிய error பொருள்களின் விலையில். எட்டு டூல் schemas இல் கையால் செய்த பதிப்பு வெல்கிறது. எண்பதில் அது வெல்லாது.

சோதித்தல்

பதினான்கு சோதனைகள், இணையத் தொடர்பின்றி, ஒரு வினாடியில் பத்தில் ஒரு பங்கிற்கும் குறைவாக. தொகுதியை contracts.py ஆகவும் சோதனைகளை test_contracts.py ஆகவும் சேமிக்கவும்; python3 -m unittest test_contracts -v இயக்கவும். முழு தொகுப்பும் களஞ்சியத்தில் உள்ளது, ஆனால் இந்த ஐந்து வடிவமைப்பைத் தாங்குகின்றன:

import unittest
import urllib.error
from contracts import (
AgentLoop, ErrorCode, ScriptedLLM, Tool, ToolError, ToolExecutor, ToolResult,
IdempotencyStore, RetryPolicy, RetryingLLM, LLMClient, build_tools,
validate_args, describe_schema,
)
class Flaky:
def __init__(self, failures, code=ErrorCode.TIMEOUT):
self.failures, self.code, self.calls = failures, code, 0
def __call__(self, args):
self.calls += 1
if self.calls <= self.failures:
raise ToolError("transient", self.code)
return ToolResult(ok=True, data="recovered")
def tool_with(fn, name="probe", side_effect=False, timeout_s=1.0):
return Tool(name=name, description="probe", _fn=fn,
parameters={"type": "object", "properties": {},
"additionalProperties": False},
side_effect=side_effect, timeout_s=timeout_s)
class TestContracts(unittest.TestCase):
def test_bool_is_not_an_integer(self):
schema = build_tools()[0].parameters
errors = validate_args(schema, {"query": "ok", "limit": True})
self.assertTrue(any("expected integer" in e["message"] for e in errors))
def test_transient_failure_is_retried_until_success(self):
flaky = Flaky(failures=2, code=ErrorCode.UPSTREAM)
executor = ToolExecutor({"probe": tool_with(flaky)}, sleep=lambda d: None)
result = executor.execute("probe", {})
self.assertTrue(result.ok)
self.assertEqual(result.attempts, 3)
def test_permanent_failure_is_never_retried(self):
flaky = Flaky(failures=5, code=ErrorCode.PERMISSION)
executor = ToolExecutor({"probe": tool_with(flaky)}, sleep=lambda d: None)
result = executor.execute("probe", {})
self.assertFalse(result.ok)
self.assertEqual(flaky.calls, 1)
def test_side_effect_runs_once_per_key(self):
calls = {"n": 0}
def write(args):
calls["n"] += 1
return ToolResult(ok=True, data="written")
executor = ToolExecutor({"probe": tool_with(write, side_effect=True)},
store=IdempotencyStore(), sleep=lambda d: None)
executor.execute("probe", {})
second = executor.execute("probe", {})
self.assertEqual(calls["n"], 1)
self.assertTrue(second.from_cache)
def test_401_is_not_retried(self):
class Bad(LLMClient):
def __init__(self):
self.calls = 0
def complete(self, messages, tools):
self.calls += 1
raise urllib.error.HTTPError("http://x", 401, "no", None, None)
inner = Bad()
llm = RetryingLLM(inner, sleep=lambda d: None)
with self.assertRaises(urllib.error.HTTPError):
llm.complete([], [])
self.assertEqual(inner.calls, 1)
if __name__ == "__main__":
unittest.main()

test_bool_is_not_an_integer சிறுபிழையாகத் தோன்றுகிறது, அதுவல்ல: {"limit": true} க்கும் அமைதியாக வெட்டப்பட்ட முடிவுத் தொகுப்பிற்கும் இடையே நிற்கும் ஒரு வரி அது. test_side_effect_runs_once_per_key latency ஐ அல்ல, தரவைப் பாதுகாக்கும் ஒரே சோதனை. இரண்டு சோதனைகளை வைத்தால், அவற்றை வையுங்கள்.

மற்றொரு கைமுறை சோதனை: Flaky ஐ RATE_LIMITED இல் max_attempts=99 உடன் சுட்டிக்காட்டி, executor கொள்கை எல்லையில் நிற்பதை உறுதிப்படுத்தவும். எல்லையற்ற retry லூப் என்பது கூடுதல் படிகளுடன் கூடிய ஒரு outage.

பயிற்சிகள்

  1. செயல்முறை-கடந்த idempotency. IdempotencyStore ஐ (name, args_hash) மற்றும் created_at timestamp ஆல் key செய்யப்பட்ட SQLite-அடிப்படையிலான பதிப்பால் மாற்றவும். பத்து நிமிடங்களைவிட பழமையான keys ஐ காலாவதி செய்யவும். ஒரு செயல்முறை write நடுவில் இறக்கும் failure முறையில் என்ன மாற்றம் ஏற்படுகிறது, மற்றும் TTL உங்கள் நீண்ட retry சாளரத்தைவிட நீளமாக ஏன் இருக்க வேண்டும்?
  2. டூல்-வாரியான retry மேலெழுத்தல். ஒரு search backend கடுமையாக rate-limit செய்கிறது; ஒரு note write அதிகபட்சம் ஒருமுறை retry செய்யப்பட வேண்டும். policy field ஐ Tool இல் சேர்த்து executor இயல்புநிலையை மேலெழுத வைக்கவும், 429 இன் கீழ் save_note call நான்கு முயற்சிகளுக்குப் பதிலாக இரண்டுக்குப் பிறகு திரும்புவதை நிரூபிக்கும் ஒரு சோதனை எழுதவும்.
  3. ரசீதுடன் coercion. {"limit": "3"} ஐ நிராகரிப்பதற்குப் பதிலாக, அதை ஏற்று 3 ஆக மாற்றி, டூல் முடிவில் ஒரு குறிப்பைச் சேர்க்கவும்: coerced: limit "3" -> 3. 50-call trace இல் இது எத்தனை திருப்பங்களைச் சேமிக்கிறது என்பதை அளக்கவும். எது அபாயகரமானது — அமைதியான coercion ஆ நிராகரிக்கப்பட்ட call ஆ — ரசீது என்ன மாற்றுகிறது?

பயிற்சி 3 தான் ஆர்வமுடையது, ஏனெனில் அதற்கு ஒரே சரியான பதில் இல்லை. Coercion round trips ஐக் குறைக்கிறது, மாடல் பிழைகளை மறைக்கிறது; நிராகரிப்பு உயர்ந்ததும் மெதுவானதும். ரசீது என்பது சமரசம்: round trip திரும்பக் கிடைக்கிறது, மாடல் சார்பாக நீங்கள் செய்த ஒவ்வொரு ஊகத்திற்குமான audit trail தக்கவைக்கப்படுகிறது.

அடுத்தது என்ன

உங்கள் டூல்களுக்கு இப்போது ஒப்பந்தங்கள் உள்ளன, தோல்விகளுக்கு codes உள்ளன, retry கள் write ஐ நகலாக்க முடியாது. Part 1 முதல் மாறாதது தான் உற்பத்தியில் முதலில் காயப்படுத்தும்: ஒவ்வொரு படியிலும் செய்தி பட்டியல் வளர்கிறது, ஒவ்வொரு call இலும் முந்தைய ஒவ்வொரு செய்தியும் முழுமையாக மீண்டும் அனுப்பப்படுகிறது.

Part 3, Context budget engineering, ஒரு ContextBudget ஐச் சேர்க்கிறது, அது ஒவ்வொரு call க்கும் முன் tokens ஐ அளந்து, system prompt, டூல் முடிவுகள், வரலாறு ஆகியவற்றுக்கிடையே சாளரத்தைப் பிரித்தொதுக்கி, மதிப்பீடு பட்ஜெட்டை மீறும்போது பழைய திருப்பங்களை சுருக்குகிறது. Part 1 அட்டவணையிலிருந்து இருபடி உள்ளீட்டு வளர்ச்சியையும் அது அளக்கிறது, மூன்று சுருக்க உத்திகள் — truncate, summarise, evict — இல் எது உண்மையில் பலனளிக்கிறது என்பதைக் காட்டுகிறது. நீங்கள் உருவாக்கிய ToolExecutor சரியாக அப்படியே இருக்கும்; பட்ஜெட்டு டூல்களை அல்ல, வரலாற்றை மூடுகிறது.

Get Ball — Ball

Get Ball

Reading in English? Switch language in the menu.