Agent Runtime & Harness
Agent loop, tool execution, context assembly, permission, budget và termination condition.
Agent là model chạy trong vòng lặp quan sát–quyết định–hành động. Harness là runtime kiểm soát context, tool, quyền, state, budget và điều kiện kết thúc.
Những điều cần nắm chắc
Model đề xuất hành động; harness validate, authorize và thực thi.
Tool description không phải security boundary.
Mọi agent loop cần step budget và điều kiện dừng.
Working context, conversation state và persistent memory là ba lớp khác nhau.
Nội dung bài viết
Một model mạnh vẫn có thể tạo agent yếu
Nếu harness cung cấp context sai, tool mơ hồ, quyền quá rộng hoặc không có recovery, model thông minh hơn chỉ giúp hệ thống mắc lỗi một cách thuyết phục hơn.
Harness phải sở hữu sandbox, approval, timeout, retry, compaction, tracing và termination. Authorization không được giao cho model tự quyết định.
Code & cấu trúc tham khảo
Agent loop có guardrail
1for (let step = 0; step < MAX_STEPS; step++) {2 const decision = await model.respond(context);3 if (decision.type === 'final') return decision.output;45 const call = validateToolCall(decision.toolCall);6 await authorize(call, userPolicy);7 const observation = await runInSandbox(call);8 context = compact([...context, decision, observation]);9}1011throw new Error('Agent step budget exceeded');Takeaway: Model chọn bước tiếp theo nhưng code đáng tin cậy vẫn kiểm soát quyền, thực thi và giới hạn.
Tài liệu đọc thêm
Repo, đặc tả và bài viết gốc để đi sâu sau bài học.
Function calling
Contract và vòng đời của tool call.
MCP and Connectors
Kết nối agent với tool và dữ liệu bên ngoài.
OpenAI — Model guidance for tool orchestration
Leaner prompts, approval boundaries và chọn direct hay programmatic tool calling.
Anthropic — Building effective agents
Agent loop và các workflow primitive trước khi dùng framework phức tạp.
Model Context Protocol specification
Protocol boundary giữa host, client, server, tools và resources.