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.

Definition 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_calls in the response;
  • execute an allowed function and return its result as a role: tool message;
  • 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

StageCapabilityStart here
1. QuickstartCreate a key, find a model, and make the first requestQuickstart
2. ConceptsUnderstand context, tools, loops, state, and permissionsCore concepts below
3. APIBuild a loop with tools, streaming, and multi-turn messagesChat Completions API
4. IntegrationsConnect the same model capability to a CLI, IDE, or appIntegration guides
5. ObservabilityInspect intent, sessions, file activity, tools, and delivery evidenceHarness Inspector
6. ProductionManage keys, usage, recovery, releases, and reuseComplete integration

Six core agent concepts

ConceptQuestion it answersMinimum practice
GoalWhat must be delivered?Turn the natural-language request into an observable result and boundary.
ContextWhich facts may the agent use?Provide only the files, messages, rules, and history needed for the task.
ModelWho 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.
ToolsWhich external actions can be requested?Document each tool, its JSON Schema, permission, and failure result.
LoopDoes the agent continue after a tool result?Set a step limit, timeout, and explicit stop conditions.
VerifyHow do we know it is done?Use tests, diffs, structure checks, human approval, or an acceptance list.
agent-looptext
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 deliver

The 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

  1. Prepare input. Create an API key and use GET /v1/models to select a model visible to the account.
  2. Run a normal request first. Follow Quickstart and verify choices[0].message.
  3. Declare one read-only tool. Start with project status, task status, or file listing. Do not open delete, publish, or payment actions first.
  4. Inspect the tool call. Parse the tool name, call ID, and JSON arguments, then validate them against a local schema.
  5. Execute and return. Execute an allowed function and append the result as a role: tool message in the same conversation.
  6. 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

tool-calling-request.shbash
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.

agent-loop.jsjavascript
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

GoalStart withTrade-off
Validate the APIcURLFewest dependencies; ideal for the first request and health checks.
Build your own agent servicePython SDKFlexible for state, loops, retries, and tests; you own the executor.
Integrate into a JavaScript appNode.js SDKGood for services and queues; keep keys on the server.
Use a coding agentCodex CLIFastest path to files, commands, and verification; permissions matter.
Work inside an IDECursorGood for inspect-edit-run-review loops; preserve diffs and tests.
Build a knowledge or business appDifyUseful for workflow orchestration; business-layer permissions remain yours.

Choose a tool guide

Observability, 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.

Production acceptance checklist

agent-production-checklist.txttext
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 sources

Troubleshooting order

SymptomCheck firstNext step
401 / authenticationAuthorization header, key validity, and environment variablesAuth & Billing
404 / model or pathBase URL, endpoint, model ID, and account visibilityList models, then Error Codes
429 / rate limitConcurrency and whether retries are piling upReduce concurrency and add exponential backoff.
Model does not call a toolTool description, schema, tool_choice, and model capabilityStart with one read-only tool and a short prompt.
Loop stops after the tool callassistant tool_calls, tool_call_id, and role=tool message orderCompare with the function-calling API example.
Task stalls or failsLast successful step, tool timeout, context, and resource budgetRecover from the smallest failed step

Practice task

Build a read-only project-status agent:

  1. Declare get_project_status, returning environment, version, test status, and latest release result.
  2. Require the model to use the tool when the user asks for current status; it must not guess.
  3. Simulate a successful tool result and a timeout, then verify both responses.
  4. Write each step to JSONL or a database with call ID, arguments, result, and duration.
  5. 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