Repository navigation
@graphai/anthropic [email protected] - #1215
Conversation
WalkthroughExported a message-conversion function and added tests; bumped package versions for two llm_agents packages. No other API, dependency, or manifest changes. Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Test Runner
participant Conv as convOpenAIToolsToAnthropicToolMessage
participant Input as OpenAI-style Messages
participant Output as Anthropic-style Messages
Test->>Conv: call convOpenAIToolsToAnthropicToolMessage(Input)
Conv->>Input: parse messages (user, assistant with tool_calls, tool messages)
Conv->>Output: emit user, assistant (with tool_use array), user (tool_results), assistant summary, next user query
Test->>Output: assert expected sequence and contents
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
llm_agents/anthropic_agent/package.json(1 hunks)llm_agents/tools_agent/package.json(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build (24.x)
- GitHub Check: build (22.x)
🔇 Additional comments (1)
llm_agents/anthropic_agent/package.json (1)
3-3: Version bump to 2.0.8 verified and good to go
- llm_agents/anthropic_agent/package.json is now at
@graphai/[email protected]- Downstream agents/llm_agents/package.json uses
"@graphai/anthropic_agent": "^2.0.7", which includes 2.0.8 (no hard-pins)- No git tags found for this package—please create a
[email protected]tag and draft release notes as needed
| { | ||
| "name": "@graphai/tools_agent", | ||
| "version": "1.0.3", | ||
| "version": "1.0.4", |
There was a problem hiding this comment.
💡 Verification agent
🧩 Analysis chain
Version bump to 1.0.4 looks good.
Patch release aligns with the PR objective and no unintended manifest changes are present.
Run this script to double-check that the versions in both packages match the PR intent and to see if any other workspace packages pin @graphai/tools_agent and may need range updates:
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Verifying package versions..."
jq -r '.name + "@" + .version' llm_agents/tools_agent/package.json llm_agents/anthropic_agent/package.json
echo
echo "Searching for workspace dependencies referencing @graphai/tools_agent..."
rg -nP -C2 '"@graphai/tools_agent"\s*:\s*"[^\"]+"' --glob '!**/node_modules/**' --glob '!**/dist/**' --glob '!**/lib/**' || echo "No dependents found or none pin a version."Length of output: 871
Update workspace dependency for @graphai/tools_agent
Please update the version specifier in your workspace manifest to match the bumped release:
• File: agents/llm_agents/package.json
Change:
- "@graphai/tools_agent": "^1.0.2"
+ "@graphai/tools_agent": "^1.0.4"All other package versions are correct and no further pins were found.
Once that change is applied, this patch is good to merge.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| "version": "1.0.4", | |
| "dependencies": { | |
| "@graphai/tools_agent": "^1.0.4", | |
| // …other dependencies… | |
| } |
🤖 Prompt for AI Agents
llm_agents/tools_agent/package.json around lines 3 to 3: the workspace
dependency version for @graphai/tools_agent is out of sync with the bumped
release; update the version specifier in your workspace manifest
(agents/llm_agents/package.json) to the new release version used across the repo
so the workspace entry matches the bumped release, and verify any workspace
dependency references to @graphai/tools_agent use that exact new version.
There was a problem hiding this comment.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
llm_agents/anthropic_agent/src/anthropic_agent.ts (1)
139-187: Export looks good; tighten typing and support OpenAI’s function-shaped tool_calls (and stringified args).Right now this utility is loosely typed (any) and assumes tool_calls have top-level name/arguments objects. To make it robust and future-proof:
- Return Anthropic.MessageParam[].
- Use Anthropic.ContentBlockParam[] for content construction.
- Support both OpenAI shapes: tool.function.{name,arguments} and top-level {name,arguments}.
- Safely JSON-parse string arguments; fall back gracefully.
- Guard when appending tool_result to ensure last.content is an array.
Suggested diff:
-export const convOpenAIToolsToAnthropicToolMessage = (messages: any[]) => { - return messages.reduce((tmp: any[], message: any) => { +export const convOpenAIToolsToAnthropicToolMessage = (messages: any[]): Anthropic.MessageParam[] => { + return messages.reduce((tmp: Anthropic.MessageParam[], message: any) => { if (message.role === "assistant" && message.tool_calls) { - const content: { type: string; text?: string; id?: string; name?: string; input?: unknown }[] = [ + const content: Anthropic.ContentBlockParam[] = [ { type: "text", - text: message.content, + text: String(message.content ?? ""), }, ]; - message.tool_calls.forEach((tool: { id: string; name: string; arguments: unknown }) => { - const { id, name, arguments: args } = tool; - - content.push({ - type: "tool_use", - id, - name, - input: args, - }); - }); - tmp.push({ - role: "assistant", - content, - }); + const safeParseJSON = (val: unknown) => { + if (typeof val === "string") { + try { + return JSON.parse(val); + } catch { + return val; + } + } + return val; + }; + message.tool_calls.forEach((tool: any) => { + const id = tool.id; + const name = tool?.function?.name ?? tool?.name; + const rawArgs = tool?.function?.arguments ?? tool?.arguments; + const input = safeParseJSON(rawArgs); + content.push({ + type: "tool_use", + id, + name, + input, + } as Anthropic.ContentBlockParam); + }); + tmp.push({ role: "assistant", content } as Anthropic.MessageParam); } else if (message.role === "tool") { const last = tmp[tmp.length - 1]; - if (last?.role === "user" && last?.content?.[0]?.type === "tool_result") { - tmp[tmp.length - 1].content.push({ + if (last?.role === "user" && Array.isArray(last?.content) && last?.content?.[0]?.type === "tool_result") { + (tmp[tmp.length - 1] as any).content.push({ type: "tool_result", tool_use_id: message.tool_call_id, content: message.content, }); } else { - tmp.push({ + tmp.push({ role: "user", content: [ { type: "tool_result", tool_use_id: message.tool_call_id, content: message.content, }, ], - }); + } as Anthropic.MessageParam); } } else { - tmp.push(message); + tmp.push(message as Anthropic.MessageParam); } return tmp; - }, []); + }, [] as Anthropic.MessageParam[]); };
🧹 Nitpick comments (4)
llm_agents/anthropic_agent/src/anthropic_agent.ts (1)
139-187: Consider documenting the expected input/output message shapes.A brief JSDoc helps prevent misuse (e.g., passing Anthropic-shaped messages in). Note we convert OpenAI-like tool_calls + tool messages into Anthropic’s tool_use/tool_result blocks.
I can add a concise JSDoc describing accepted OpenAI variants and the Anthropic output schema if you’d like.
llm_agents/anthropic_agent/tests/test_conv_messages.ts (3)
5-6: Avoid exporting test fixtures from the test module.No consumer needs this symbol; keeping it local reduces accidental coupling.
Apply this diff:
-export const messages = [ +const messages = [
141-141: Remove commented debug code.Leftover console logs add noise; tests should be quiet by default.
Apply this diff:
-//console.log(JSON.stringify(convOpenAIToolsToAnthropicToolMessage(messages)));
145-176: Test scenario is solid; add compatibility cases to prevent regressions.Consider adding tests for:
- tool_calls using OpenAI’s function shape (tool.function.{name,arguments} with stringified arguments).
- Mixed sequences where tool messages are interrupted or there are no tool_calls (ensure pass-through behavior).
I can author these additional tests to lock in behavior across both OpenAI variants.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
llm_agents/anthropic_agent/src/anthropic_agent.ts(1 hunks)llm_agents/anthropic_agent/tests/test_conv_messages.ts(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
llm_agents/anthropic_agent/src/anthropic_agent.ts (2)
llm_agents/anthropic_agent/lib/anthropic_agent.js (1)
convOpenAIToolsToAnthropicToolMessage(94-144)llm_agents/anthropic_agent/tests/test_conv_messages.ts (1)
messages(5-139)
llm_agents/anthropic_agent/tests/test_conv_messages.ts (1)
llm_agents/anthropic_agent/src/anthropic_agent.ts (1)
convOpenAIToolsToAnthropicToolMessage(139-187)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build (22.x)
- GitHub Check: build (24.x)
🔇 Additional comments (1)
llm_agents/anthropic_agent/tests/test_conv_messages.ts (1)
1-1: Ensure TS loader is configured for anthropic_agent testsWe’ve confirmed:
• The root workspace has ts-node hoisted in devDependencies.
• llm_agents/anthropic_agent/package.json defines
– “test”: “echo hello”
– “test_run”: “node --test --require ts-node/register ./tests/run_.ts”
• Tests under tests/.ts import directly from src/anthropic_agent.Next steps:
• Confirm your CI/test pipeline invokes the loader-equipped command (e.g.yarn workspace anthropic_agent test_runor similar) so Node can import.tsfiles fromsrc.
• Or unify the package’stestscript to run TS tests directly:"scripts": { - "test": "echo hello", + "test": "node --test --require ts-node/register ./tests/run_*.ts", "test_run": "node --test --require ts-node/register ./tests/run_*.ts" }• If you instead intend to test against compiled output, update imports in
tests/from../src/anthropic_agentto../lib/anthropic_agentand ensure a build step runs first.
Summary by CodeRabbit