Skip to content

Ground cleaned-up quotes; add a TypeScript tool-calling diagram agent - #4

Merged
Hussaincodes01 merged 3 commits into
mainfrom
claude/loving-ritchie-qc78k9
Nov 2, 2026
Merged

Hussaincodes01 merged 3 commits into
mainfrom
claude/loving-ritchie-qc78k9

Conversation

@Hussaincodes01

Copy link
Copy Markdown
Owner

1. Grounding: articles were coming out empty (06e31f9)

"Attention Is All You Need" shipped with 2 concepts and 0 visuals.

  • Cause 1, strict matching. The free model quoted the paper with its LaTeX cleaned up (for example "dimension d_k" instead of dimension $d_k$, with straightened quotes and citations dropped). Grounding accepted only exact or whitespace-collapsed matches, so most quotes were dropped.
  • Cause 2, the cascade. An opportunity whose concept had been dropped went too, unless another grounded concept shared its section.

What changes:

  • Tolerant matching. span_for_text now falls back to a normalised comparison: TeX commands and citations removed, quotes and dashes folded, case ignored. Matches are mapped back to exact raw offsets, so a span still points at real characters of the paper.
  • Partial copies. A partly copied quote grounds to its longest verbatim run, if that run is at least 8 words and 60% of the quote. Text the paper never wrote still fails, and tests cover that.
  • Wrong section. A quote not found in its cited section is searched for in the other sections.
  • No cascade. A grounded opportunity whose concept failed to ground now creates that concept from its own claim and span.
  • Rebuild. PIPELINE_VERSION is now 0.3.1-grounding, so the two weak cached articles are rebuilt.

2. TypeScript diagram agent (79b3c66)

reader/app/api/diagram is an agent harness in the reader's Next.js app. It runs server-side, so the key never reaches a browser. A model draws a concept_diagram by calling three tools, each checked as it is called:

Tool Does Answers with
draw sets every element and arrow unknown ids, two elements in one cell, self-loops
script sets every step unknown ids, marks on elements without items, runtime over 70 s (measured with planConceptDiagram, the browser's own animation code)
finish submits refusal with reasons while problems remain
  • Turns. The prompt asks for draw and script together, so a diagram is usually 2 turns. A problem costs one more turn in the same conversation, not a full regeneration.
  • Reasoning. It is capped at 800 tokens, and reasoning_details is passed back between turns.
  • Timeouts. Each call has its own 90 s limit inside the overall deadline. A slow, spent or withdrawn free model hands over to the next model with time left for it to answer.
  • Access. The route refuses every request without ARCVISUAL_INTERNAL_SECRET.
  • Python side. The pipeline uses the agent for a concept diagram's first attempt when ARCVISUAL_DIAGRAM_AGENT_URL and ARCVISUAL_INTERNAL_SECRET are set, and validates the result the same way as one-shot output. Any failure falls back to one-shot generation.

Verification

  • pytest passes (11 new grounding tests, 8 new agent tests). ruff is clean.
  • Reader: npm test (17 vitest cases, now in CI), tsc --noEmit and next build pass.
  • Locally, the route returns 401 without the secret or with a wrong one, and 503 without an OpenRouter key.
  • Before building, a probe against the free Nemotron endpoint confirmed it supports tool calling and returns reasoning_details: a draw turn took 16 s and a finish turn 0.4 s.

Deploying (not done yet)

  • Reader project: set ARCVISUAL_INTERNAL_SECRET and OPENROUTER_API_KEY.
  • API project: set the same secret, and ARCVISUAL_DIAGRAM_AGENT_URL=https://arcvisual.vercel.app/api/diagram.
  • Then deploy both projects.

Generated by Claude Code

…g an article

"Attention Is All You Need" shipped with two concepts and no visuals. The
free model quoted the paper with its LaTeX tidied ("dimension d_k" for
"dimension $d_k$", curly quotes, citations dropped), and grounding only
accepted exact or whitespace-collapsed matches, so most quotes were dropped.
Every opportunity whose concept was among them then went too, unless another
grounded concept shared its section.

- span_for_text falls back to matching a normalised view (TeX commands and
  citations removed, quotes and dashes folded, case-insensitive) mapped back
  to exact raw offsets, so a span still points at real text of the paper. A
  partly copied quote grounds to its longest verbatim run when that run is at
  least 8 words and 60% of the quote; anything less still fails.
- A quote not found in its cited section is searched for in the others; the
  attribution is corrected, the text is unchanged.
- A grounded opportunity whose concept did not ground creates that concept
  from its own claim and span instead of being dropped.
- PIPELINE_VERSION -> 0.3.1-grounding, so the two weak cached articles are
  rebuilt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BgiEmhLGtyG2FWJkiiwD1M
reader/app/api/diagram is a small agent harness in the reader's Next.js app
(server-side; the key never reaches a browser). A model draws a
concept_diagram by calling three tools, each checked as it is called:

- draw sets every element and arrow, and answers with problems: unknown ids,
  two elements in one cell, self-loops, duplicate arrows;
- script sets every step, and answers with unknown ids, marks on elements
  without items, and runtime over 70s, measured with planConceptDiagram, the
  code that animates the scene in the browser;
- finish submits, refused with reasons while problems remain.

The prompt asks for draw and script in the first turn, so a diagram usually
takes two turns; a problem costs one more turn in the same conversation
instead of a full regeneration. reasoning_details is passed back between
turns. Each call has its own timeout (90s) inside the overall deadline, so a
slow, spent or withdrawn free model hands over to the next model with time
left for it to answer. The route refuses every request without
ARCVISUAL_INTERNAL_SECRET.

The Python pipeline asks the agent for a concept diagram's first attempt
when ARCVISUAL_DIAGRAM_AGENT_URL and ARCVISUAL_INTERNAL_SECRET are set,
passing the remaining step budget, and validates the result exactly as it
does one-shot output. Not configured, unreachable, out of time or no
accepted diagram: it falls back to one-shot generation.

Tests: 17 vitest cases for the tools, loop and client (npm test, now in CI);
8 pytest cases for the Python seam.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BgiEmhLGtyG2FWJkiiwD1M
Copilot AI balanced review requested due to automatic review settings November 2, 2026 06:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T06:53:55.427231Z 79b3c66 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 79b3c66c1b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

beats = fit_beats(captions, MIN_BEAT_S * 2 * len(captions))
note = f"drawn by the diagram agent in {drawn.turns} turn(s) on {drawn.model}"
# Tokens were spent by the agent's own calls, which report no price.
return drawn.params, beats, False, Usage(attributed=False), [note, *drawn.notes]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include paid agent calls in the scene budget

When the default free endpoint is exhausted or times out, the agent can fall through to paid models, but this reports zero cost and discards the token usage returned by the route. build_scene adds GenerateResult.cost_usd to its spend before checking the per-scene ceiling, so these paid turns are invisible to both the ceiling and the job total. Price the agent usage or prevent unpriced paid fallbacks.

Useful? React with 👍 / 👎.

Comment thread reader/lib/harness/diagramTools.ts Outdated
caption: { type: "string", description: "One plain sentence, under 90 characters." },
show: { type: "array", items: { type: "string" } },
focus: { type: "array", items: { type: "string" } },
flow: { type: "array", items: { type: "string" }, description: "A path of element ids, in order." },

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Enforce the template's eight-stop flow limit

If the model emits a flow with more than eight IDs, this tool schema accepts it and checkScript checks references and runtime but not flow length; finish can therefore accept a result that arcvisual/templates/concept_diagram.py rejects because Step.flow is limited to eight items. Codegen then spends a failed first attempt and retries via one-shot generation. Add the matching limit to the tool schema or checker.

Useful? React with 👍 / 👎.

A live run against the free Nemotron endpoint with separate draw / script /
finish tools produced a good diagram but used all five turns (75s): the model
called the tools one at a time, and each turn costs ~15s there. One tool now
takes the whole diagram and is accepted the moment it has no problems, listing
every problem at once otherwise, so the good case is one turn and each fix one
more. Turn cap 5 -> 4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BgiEmhLGtyG2FWJkiiwD1M
@Hussaincodes01
Hussaincodes01 merged commit 9c24032 into main Nov 2, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants