Agent topic: from the first API call to a recoverable workflow
A practical learning path for building agents with gpt88.cc: start with one verified request, then add tool calling, context, loops, permissions, observability, and production checks.
What this topic solves
Many agent projects stop at one of three gaps: the API works but the model cannot use tools; tools work but there is no state, step limit, or permission boundary; or the task finishes but the team cannot explain, recover, or reuse the successful path.
This topic connects GPT88 API references, model discovery, developer-tool integrations, and engineering guides into one route: quickstart, core concepts, developer API, tool integrations, observability, production, and troubleshooting.
Quickstart
Create a key and verify the first request.
Open topic sectionCore concepts
Understand context, tools, loops, state, and permissions.
Open topic sectionDeveloper API
Use tools, streaming, and multi-turn messages.
Open topic sectionTool integrations
Connect Claude Code, Codex CLI, Cursor, Cline, or Dify.
Open topic sectionObservability
Trace intent, sessions, file activity, and delivery evidence.
Open topic sectionProduction
Cover keys, usage, retries, and release checks.
Open topic sectionDefinition of done
You do not need to read every page. The minimum outcome is that you can:
- run a minimal request with an
API Key + Base URL + model ID; - declare a tool and inspect
tool_callsin the response; - execute an allowed function and return its result as a
role: toolmessage; - set step limits, timeouts, allowed actions, and human-approval boundaries;
- record request IDs, tool inputs, tool outputs, failures, and the final artifact;
- recover from 401, 404, 429, timeout, and tool-execution failures.
Recommended learning path
| Stage | Capability | Start here |
|---|---|---|
| 1. Quickstart | Create a key, find a model, and make the first request | Quickstart |
| 2. Concepts | Understand context, tools, loops, state, and permissions | Core concepts below |
| 3. API | Build a loop with tools, streaming, and multi-turn messages | Chat Completions API |
| 4. Integrations | Connect the same model capability to a CLI, IDE, or app | Integration guides |
| 5. Observability | Inspect intent, sessions, file activity, tools, and delivery evidence | Harness Inspector |
| 6. Production | Manage keys, usage, recovery, releases, and reuse | Complete integration |
Six core agent concepts
| Concept | Question it answers | Minimum practice |
|---|---|---|
| Goal | What must be delivered? | Turn the natural-language request into an observable result and boundary. |
| Context | Which facts may the agent use? | Provide only the files, messages, rules, and history needed for the task. |
| Model | Who plans and generates the next step? | Use <Link to="/en/docs/api/list-models/">GET /v1/models</Link> to confirm availability for the current key. |
| Tools | Which external actions can be requested? | Document each tool, its JSON Schema, permission, and failure result. |
| Loop | Does the agent continue after a tool result? | Set a step limit, timeout, and explicit stop conditions. |
| Verify | How do we know it is done? | Use tests, diffs, structure checks, human approval, or an acceptance list. |
User goal
↓
Read context → plan next step → call the model
↓
Need a tool? ── no ──→ return answer
│ yes
↓
execute and record the tool
↓
continue loop
↓
verify and deliverThe model proposes a tool call; your application or client executes it. Validate the tool name and arguments, decide whether the action is allowed, and return a structured result. A model request is not the same thing as an executed action.
Shortest success path: run one tool call
- Prepare input. Create an API key and use GET /v1/models to select a model visible to the account.
- Run a normal request first. Follow Quickstart and verify
choices[0].message. - Declare one read-only tool. Start with project status, task status, or file listing. Do not open delete, publish, or payment actions first.
- Inspect the tool call. Parse the tool name, call ID, and JSON arguments, then validate them against a local schema.
- Execute and return. Execute an allowed function and append the result as a
role: toolmessage in the same conversation. - Verify the final result. Check the tool result, conclusion, and output format instead of only checking that text was returned.
What the application does after a tool call
curl https://api.gpt88.cc/v1/chat/completions \
-H "Authorization: Bearer $GPT88_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "YOUR_MODEL_ID",
"messages": [
{"role": "user", "content": "Check the current project release status"}
],
"tools": [{
"type": "function",
"function": {
"name": "get_project_status",
"description": "Read the current environment, version, and release status",
"parameters": {
"type": "object",
"properties": {},
"additionalProperties": false
}
}
}],
"tool_choice": "auto"
}'Wrap calls in a recoverable loop
A prototype can handle one tool call manually. A real service needs an execution state that stores the goal, message history, tool calls, results, errors, timing, and final artifact.
const state = {
goal,
messages: [{ role: "user", content: goal }],
steps: [],
maxSteps: 8,
}
while (state.steps.length < state.maxSteps) {
const response = await callModel(state.messages, tools)
const toolCalls = response.choices?.[0]?.message?.tool_calls ?? []
if (toolCalls.length === 0) {
return verifyAndDeliver(response.choices[0].message.content)
}
state.messages.push(response.choices[0].message)
for (const call of toolCalls) {
const args = JSON.parse(call.function.arguments || "{}")
const result = await executeAllowedTool(call.function.name, args)
state.steps.push({ call, result })
state.messages.push({
role: "tool",
tool_call_id: call.id,
content: JSON.stringify(result),
})
}
}
throw new Error("agent step limit reached")A production implementation should also add:
- parameter schema validation and a tool allow-list;
- timeouts, retries, exponential backoff, and idempotency keys;
- redaction, log retention, and an end-user identifier;
- step, cost, and resource budgets;
- pause-for-approval, safe rollback, and resume policies.
Choose an integration style
| Goal | Start with | Trade-off |
|---|---|---|
| Validate the API | cURL | Fewest dependencies; ideal for the first request and health checks. |
| Build your own agent service | Python SDK | Flexible for state, loops, retries, and tests; you own the executor. |
| Integrate into a JavaScript app | Node.js SDK | Good for services and queues; keep keys on the server. |
| Use a coding agent | Codex CLI | Fastest path to files, commands, and verification; permissions matter. |
| Work inside an IDE | Cursor | Good for inspect-edit-run-review loops; preserve diffs and tests. |
| Build a knowledge or business app | Dify | Useful for workflow orchestration; business-layer permissions remain yours. |
Choose a tool guide
Claude Code
Terminal-based coding agent with project context and Claude-style routing.
Open guideCodex CLI
Command-line workflow for edits, tools, verification, and delivery.
Open guideCursor / Cline
Inspect and modify code inside an editor while keeping a review loop.
Open guideDify / AnythingLLM
Connect models to apps, workflows, knowledge bases, and team services.
Open guideObservability, permissions, and recovery
Agent quality is not only the final answer. Track whether the agent followed the right path. A useful task record includes the goal, model, request ID, message summary, tool name, argument summary, result, error, approval point, and final artifact location.
- Harness Inspector: connect intent, sessions, file activity, and commits into delivery evidence.
- Codex Tool Recovery: diagnose missing tools and recover from the smallest failed step.
- Loop Engineering: turn successful task paths into reusable execution loops.
- Skills and context engineering: combine rules, context, permissions, and work logs.
Production acceptance checklist
Identity and configuration
- Keep API keys in server-side environment variables or a secret manager
- Never print complete keys in logs, screenshots, prompts, or frontend code
- Verify the model ID, Base URL, and account visibility
Execution and reliability
- Validate tool names and arguments with an allow-list and schema
- Set step limits, timeouts, retries, and stop conditions
- Require approval for writes, releases, messages, and deletes
- Make tool execution idempotent or safely retryable
Observability and acceptance
- Record request_id, model, duration, tools, and error summaries
- Define structured acceptance criteria for the final result
- Resume failed tasks from the last safe state
- Save successful prompts, schemas, configurations, and checklists
Before scaling
- Test quality, duration, cost, and failure rate on a small sample
- Compose tools or batch tasks only after the path is stable
- Confirm current models, pricing, limits, and response details from live sourcesTroubleshooting order
| Symptom | Check first | Next step |
|---|---|---|
| 401 / authentication | Authorization header, key validity, and environment variables | Auth & Billing |
| 404 / model or path | Base URL, endpoint, model ID, and account visibility | List models, then Error Codes |
| 429 / rate limit | Concurrency and whether retries are piling up | Reduce concurrency and add exponential backoff. |
| Model does not call a tool | Tool description, schema, tool_choice, and model capability | Start with one read-only tool and a short prompt. |
| Loop stops after the tool call | assistant tool_calls, tool_call_id, and role=tool message order | Compare with the function-calling API example. |
| Task stalls or fails | Last successful step, tool timeout, context, and resource budget | Recover from the smallest failed step |
Practice task
Build a read-only project-status agent:
- Declare
get_project_status, returning environment, version, test status, and latest release result. - Require the model to use the tool when the user asks for current status; it must not guess.
- Simulate a successful tool result and a timeout, then verify both responses.
- Write each step to JSONL or a database with call ID, arguments, result, and duration.
- Set a four-step limit and define when the agent pauses for human takeover.
Acceptance criteria:
- Without a tool result, the agent says it cannot confirm instead of inventing a status;
- after a tool failure, the user gets an actionable next step;
- request IDs and tool call IDs can reconstruct the execution;
- the same checklist can regression-test a changed model or tool schema.
Next reading
- First integration: Quickstart → Models API → Chat Completions API.
- Use a mature tool: Integration guides, then open the Claude Code, Codex CLI, Cursor, Cline, or Dify guide.
- Build for production: Complete integration → Config export → Harness Inspector.
- Handle asynchronous media tasks: Async image generation guide.