chore(weave): add weave-instrument agent skill - #7370
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
ffa1c9b to
2b1f673
Compare
| (`pyproject.toml` or `requirements.txt`, and `package.json`). Note the *exact* libraries: `openai`, | ||
| `anthropic`, `langchain`, `openai-agents` (`import agents`), `claude_agent_sdk`, `google.adk`, | ||
| `crewai`, `llama_index`, and so on. Step 3 is where you resolve whether the installed Weave |
There was a problem hiding this comment.
These package names are bit different in package.json.
| 2. **What is the structure?** The turn boundary (one input maps to one cycle), the model calls, tool | ||
| dispatch, sub-agents, and any streaming or concurrency. This is what you instrument, and it exists | ||
| whatever the library is. | ||
| 3. **Probe auto-coverage.** Do not trust a memorized list, because it rots. Check whether the |
There was a problem hiding this comment.
because it rots
v dramatic
| ## Procedure | ||
|
|
||
| 1. **What shape is wanted?** An agent-shaped tree goes to the Agents tab. Flat model-call traces | ||
| ("just my LLM calls") go to the Traces tab. |
There was a problem hiding this comment.
Looks like this might be getting renamed? https://github.com/wandb/core/pull/46847
| - **Agent-shaped, lands in the Agents tab, no extra code:** the OpenAI Agents SDK (`import agents`), | ||
| the Claude Agent SDK (`claude_agent_sdk`), and Google ADK (`google.adk`, with an import-order | ||
| caveat). |
There was a problem hiding this comment.
Should we detail the specific js packages name like we do below as well?
| The Session SDK models Session, then Turn (`invoke_agent`), then a set of LLM (`chat`), Tool | ||
| (`execute_tool`), and SubAgent (`invoke_agent`) spans. It covers loops, unknown frameworks, streaming | ||
| (hold the LLM span open, accumulate, then close it), sub-agents, async work (Python contextvars, or | ||
| TypeScript `runIsolated`), and post-hoc logging (`log_turn` or `log_session`). |
There was a problem hiding this comment.
The TS SDK doesn't have these log* fns, worth mentioning?
| for (const tc of msg.tool_calls ?? []) { | ||
| const tool = weave.startTool({name: tc.function.name, args: tc.function.arguments, toolCallId: tc.id}); | ||
| try { tool.result = await runTool(JSON.parse(tc.function.arguments)); } | ||
| finally { tool.end(); } | ||
| } |
There was a problem hiding this comment.
I believe this is in the wrong block -- msg wouldn't be in scope here.
| } finally { turn.end(); } | ||
| } finally { session.end(); } |
There was a problem hiding this comment.
Not sure if it's worth running this through prettier so the agent has example of code more similar to what users' might have set up w/their repos?
| `WANDB_API_KEY`, or call `await weave.login(apiKey)` once. The user does this; never hard-code a | ||
| key. | ||
|
|
||
| ## Canonical pattern (try/finally, because JS has no `with`, so close in `finally`) |
There was a problem hiding this comment.
Adding to our pod sync list: we should talk about some more friendly APIs to support this.
| calls, since registry membership alone does not prove it. | ||
| - If you cannot run it (because of missing provider keys or heavy setup), give the user an exact | ||
| copy-paste command to run themselves, and tell them what to look for: the printed | ||
| `https://wandb.ai/.../weave` link, and a trace in the Agents or Calls tab. |
There was a problem hiding this comment.
We call out the parameterized https://wandb.ai/<entity>/<project>/weave thing elsewhere, should we be consistent?
| test, or a tiny script that exercises one turn) and confirm that a Weave URL is printed and a trace | ||
| shows up at the project URL. |
There was a problem hiding this comment.
I don't see any urls when running the TS examples -- we have a printCallLink setting that appears only relevant to some op-related stuff. Following up in Slack, since the skill seems to be relying on this.
0f3e658 to
52bf68a
Compare
weave-instrument agent skill
Adds the
weave-instrumentskill which helps an agent add Weave to a Python or TypeScript LLM codebase based on how their code is structured. Supported instrumentation includes the OTEL auto-instrumentation, Session-based manual implementation, and a generic OTEL export.Doc:
Instrument your agent with the
weave-instrumentskillweave-instrumentis an agent skill that adds Weave tracing to an existing LLM oragent codebase. Point your agent at your project and ask it to add Weave using this skill.
It will:
weave.init();It works for Python and TypeScript!
What it does
The skill picks the right tracing approach for your code instead of applying a fixed
template. It decides based on the kind of traces you want and the structure of your code,
not on which framework you use, so it works for any agent: a known framework, an in-house
one, or a plain loop with no framework at all. It can:
Turn,LLM,Tool, andSubAgentspans) toproduce agent-shaped traces in the Weave Agents tab. This is the universal path and
works for any agent.
single
weave.init()call captures everything with no per-call code.spans or owns its own tracer.
It then verifies that traces actually arrive, and tells you the exact URL where your data
will land.
How to use it
weave-instrumentfolder wherever your coding agent loadsskills from. For Claude Code, that's
~/.claude/skills/(available in every project) or aproject's
.claude/skills/(just that project). Your agent discovers it automatically.WANDB_API_KEY(fromhttps://wandb.ai/authorize) or run
wandb login. The skill never handles your key.Your agent reads your code, proposes a short plan, makes the edits, and asks you to confirm
the project name (
entity/project).What you get
Tracing that matches how your agent is built, added without changing its behavior: the same
outputs, the same exceptions, and spans that always close. Your runs appear at
https://wandb.ai/<entity>/<project>/weave.