Last reviewed: 2026-06-10
Direct answer
When a coding agent writes code or documentation and then immediately reviews its own output using the same model call or session, the review rarely catches the underlying reasoning error — the model simply confirms what it just said. The fix is structural: route writing calls and reviewing calls through separate API paths so neither role can see the other’s intermediate reasoning.
With CometAPI you can do this at the gateway layer. You point your writer agent at one model path and your reviewer agent at a different path — or at least a fresh, isolated request — so each leg of the pipeline starts without the other’s context. The chat completions endpoint (/api/text/chat) and the Responses endpoint (/api/text/responses) are the two primary paths for this; confirm the exact request shape, auth header format, and available model identifiers for each path in the current CometAPI docs before building your routing logic.
The separation does not have to be complex. A thin shell script, a small Python wrapper, or a CI step that calls each endpoint independently is enough to enforce the boundary. The key is that the reviewer call must not inherit the writer’s conversation history, and the two roles must not share a request ID or session token.
For broader release checks, see When to Stop, Retry, or Escalate: A Practical Guide to Coding Agent Task Control .
Who this is for
This guide is for teams that:
- Run coding agents — such as Codex, Claude Code, or similar tools — in automated or semi-automated pipelines where model output reaches a pull request or a static site without a human reading every line.
- Use CometAPI as a model gateway and want to route writer and reviewer calls without letting endpoint drift silently break the separation.
- Have encountered situations where an agent’s self-review missed the same class of errors that the writer introduced.
- Want a smoke-test they can run before each deployment to verify that the separation is still intact.
If you are still evaluating whether a gateway like CometAPI fits your pipeline, the Route Coding Agent Model Calls Without Endpoint Drift guide covers the foundational routing setup.
Key takeaways
- A writer agent and a reviewer agent must start from independent context windows. Shared history defeats the purpose of the review.
- CometAPI exposes at least two text-generation endpoint families. Route each role to the correct family and verify the mapping at smoke-test time, not just at setup time.
- The reviewer’s system prompt should describe what to look for, not what the writer was trying to do. If the reviewer already knows the intent, it will rationalize rather than scrutinize.
- Log the endpoint path, request ID, and role label for every call. When a review passes a bad output, that log is the first place you look.
- Exact model IDs, rate limits, pricing, and auth field names should be read from the current CometAPI documentation at the time you configure the pipeline — they can change between your setup date and today.
Practical setup overview
Step 1 — Define the boundary in your instruction file
If your agent reads an AGENTS.md or equivalent instruction file (as described in the OpenAI Codex AGENTS.md reference), add a section that makes the separation explicit:
Model call roles
Writer calls: use WRITER_BASE_URL and WRITER_MODEL env vars. Reviewer calls: use REVIEWER_BASE_URL and REVIEWER_MODEL env vars. Do not reuse the writer’s conversation history in reviewer calls. Do not share request IDs between writer and reviewer legs.
This keeps the boundary visible to any agent that reads the instruction file and gives a human reviewer a single place to audit the configuration.
Step 2 — Configure environment variables, not hardcoded paths
Store the endpoint base URL and model identifier for each role in environment variables. Never hardcode them in agent scripts:
WRITER_BASE_URL=https://apidoc.cometapi.com # base only; append /api/text/chat or /api/text/responses WRITER_MODEL= REVIEWER_BASE_URL=https://apidoc.cometapi.com REVIEWER_MODEL=
Verify the exact model identifiers available for each path in the CometAPI model overview before populating these values. Do not assume a model ID that worked on one endpoint family will work on the other.
Step 3 — Isolate the reviewer’s context
The reviewer call must not include the writer’s message history. Pass only:
- A reviewer system prompt describing what standards to apply.
- The artifact to review (code diff, draft text, or structured output).
- No reference to how or why the writer produced that artifact.
This mirrors the pull request model described in the GitHub pull request documentation: the reviewer sees the diff, not the author’s internal reasoning, and forms an independent judgment.
Step 4 — Add the reviewer output to the PR or publish payload
Capture the reviewer’s response as a structured artifact — a JSON object works well — and attach it to the pull request description or the publish payload. A reviewer that produces no auditable output is functionally equivalent to no review at all.
See How to Hand Off Coding Agent Pull Requests for Review for the handoff checklist.
Smoke-test workflow
Setup assumptions
- You have a CometAPI API key in the environment variable COMETAPI_API_KEY.
- WRITER_BASE_URL, WRITER_MODEL, REVIEWER_BASE_URL, and REVIEWER_MODEL are set.
- You have curl and jq available.
Happy-path request plan
- Send a writer call to /api/text/chat with a minimal system prompt and a single user message. Capture the response body and the id field.
- Send a reviewer call to the same or a different endpoint path, using a fresh request (no conversation_id or prior message history from step 1). Pass only the writer output as a user message.
- Confirm that the two id values in the responses are different. A shared ID would indicate the gateway is treating them as the same session.
Error-path check
- Try sending the reviewer call with a missing or malformed Authorization header. Confirm the gateway returns a 4xx response, not a 200 with a degraded result.
- Try sending the reviewer call with the writer model identifier swapped in for the reviewer model identifier. Note whether the gateway accepts or rejects it. This tells you whether your model routing is enforced at the gateway level or only by your scripts.
Minimum assertions
- Both calls return HTTP 200.
- The writer response contains a non-empty choices or output field (verify the exact field name for your endpoint family in the CometAPI chat completions reference and the CometAPI Responses reference).
- The reviewer response contains a non-empty assessment.
- The two request IDs do not match.
Pass/fail logging fields
Record these fields after the smoke test:
smoke_test_date: YYYY-MM-DD writer_endpoint: /api/text/ reviewer_endpoint: /api/text/ writer_request_id: reviewer_request_id: writer_status: 200 | reviewer_status: 200 | ids_distinct: true | false review_field_present: true | false pass: true | false notes:
What the smoke test must not assert
- Do not assert a specific model name, price, token count, latency target, or uptime figure. These vary by account, plan, and CometAPI configuration.
- Do not assert that the reviewer “caught” a specific error in the writer output. The smoke test verifies structural separation, not review quality.
- Do not compare response bodies between writer and reviewer. Their content will legitimately differ.
Sanitized log record template
After each pipeline run that includes a writer/reviewer separation check, record a log entry similar to this:
{
"run_id": "<pipeline-run-id>",
"date": "YYYY-MM-DD",
"writer_role": {
"endpoint_family": "/api/text/<family>",
"model_label": "<env-var name, not actual model id>",
"request_id": "<masked or truncated>",
"status": 200
},
"reviewer_role": {
"endpoint_family": "/api/text/<family>",
"model_label": "<env-var name, not actual model id>",
"request_id": "<masked or truncated>",
"status": 200
},
"ids_distinct": true,
"review_artifact_attached": true,
"pass": true
}
Do not log API keys, full prompts, full responses, token counts, pricing data, or model identifiers that might expose your gateway configuration.
Failure modes
- Evidence gap: the agent cannot inspect the failing log, source page, pull request, or local command output. The safe action is to stop and record the missing evidence instead of guessing.
- Scope drift: the agent edits files that are not connected to the observed failure. Keep the repair tied to the failing signal and leave unrelated cleanup for a separate task.
- Environment mismatch: the local check uses different versions, credentials, feature flags, or runtime settings than the hosted path. Record the mismatch before treating the result as proof.
- Unreviewed fallback: the agent changes models, endpoints, permissions, or retry behavior to make a run pass without preserving the review boundary. Treat access and provider failures as operational blockers, not topic failures.
- Weak handoff: the final note says the issue is fixed but omits the command, result, changed files, and remaining uncertainty. That makes the next operator repeat the investigation.
Sources checked
- OpenAI Codex AGENTS.md guidance - accessed 2026-06-10; purpose: verify repository instruction-file context for coding agents.
- GitHub pull requests documentation - accessed 2026-06-10; purpose: verify pull request review and collaboration boundaries.
- CometAPI documentation - accessed 2026-06-10; purpose: verify current CometAPI documentation navigation.
- CometAPI chat completions reference - accessed 2026-06-10; purpose: verify chat completion contract areas.
- CometAPI responses reference - accessed 2026-06-10; purpose: verify responses endpoint contract areas.
- CometAPI models overview - accessed 2026-06-10; purpose: verify model catalog discovery guidance.
Contract details to verify
| Area | What to verify | Source URL | Accessed | Safe candidate wording |
|---|---|---|---|---|
| Chat completions request shape | Required fields, auth header name, message array structure | https://apidoc.cometapi.com/api/text/chat | 2026-06-10 | “Consult the current CometAPI chat completions reference for required request fields.” |
| Responses endpoint request shape | Whether the field names differ from chat completions; session or conversation ID handling | https://apidoc.cometapi.com/api/text/responses | 2026-06-10 | “Consult the Responses endpoint reference to confirm field names before building your reviewer call.” |
| Session or conversation isolation | Whether a request ID or conversation token can cause context to be shared across calls | https://apidoc.cometapi.com/api/text/chat | 2026-06-10 | “Verify whether any session or conversation token field could link writer and reviewer calls before relying on the separation.” |
| Instruction-file scope | Which agents read AGENTS.md and how they scope rules to subdirectories | https://github.com/openai/codex/blob/main/docs/agents_md.md | 2026-06-10 | “Confirm the instruction-file scope rules for your specific agent version.” |
| PR description attachment | How to attach structured reviewer output to a GitHub PR body or comment | https://docs.github.com/en/pull-requests | 2026-06-10 | “See the GitHub pull requests documentation for how to include structured content in PR descriptions.” |
Reader next step
Compare the workflow against Start with CometAPI .
Use When to Stop, Retry, or Escalate: A Practical Guide to Coding Agent Task Control as the next comparison point. Keep AI Coding Agent Setup, Security, and Model Routing nearby for setup and permission checks.
FAQ
Why does using the same model for writer and reviewer not work?
The same model used twice in the same session will tend to defend its first answer. Even when called in a separate request, a model that is told “review this output, which was written to satisfy X” already has the framing it needs to rationalize the output rather than scrutinize it. Structural separation — different context windows, different system prompts, no shared history — is what makes the reviewer’s judgment independent.
Can I use the same CometAPI key for both roles?
Yes, using the same API key is fine as long as the two calls are independent requests with no shared session or conversation token. The separation is about context isolation, not credential isolation. Verify the current CometAPI docs to confirm whether any request field — such as a thread ID or conversation ID — could inadvertently link the two calls.
What if the reviewer’s output is just “looks good”?
A reviewer that consistently returns low-information approvals is a signal that the system prompt is too weak or that the model is not being given enough of the right context. Provide the reviewer with a concrete rubric: what class of errors to look for, what the acceptance criteria are, and what a failing review should contain. Treat a bare “looks good” as a failed review until you have calibrated the reviewer prompt.
How do I know if my endpoint routing is still correct after a CometAPI update?
Run the smoke test described above on a schedule — for example, as a daily CI job — rather than only at initial setup. Verify the endpoint paths against the current CometAPI docs at each run. Endpoint behavior can change between your initial configuration and today.
Does this approach work with Codex, Claude Code, and other coding agents?
The separation is a property of your pipeline design, not of any specific agent. Any agent that reads an instruction file such as AGENTS.md will follow the role boundary you define there, as long as you also enforce it at the API call level. Agents that do not read instruction files require the separation to be enforced by your wrapper scripts or CI configuration.
Where can I start if I do not have a CometAPI account yet?
Visit CometAPI to get started. Confirm the current pricing and plan details in the CometAPI documentation before setting usage budgets for your writer and reviewer calls.