Skip to content

Commit 5a1d677

Browse files
authored
Merge pull request #14 from runloopai/tode/wandb-weave
Update wandb with cloud agent integration
2 parents 22e9ae5 + a446531 commit 5a1d677

10 files changed

Lines changed: 238 additions & 34 deletions

File tree

AGENTS.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,18 @@ This ensures the agent can write to `/tmp` for tax document processing without r
219219

220220
### Environment Variables
221221

222-
**Agent Server (`packages/tax-processing/.env`):**
222+
**Agent Server (`packages/tax-processing/.env`) - Local Development Only:**
223223
```env
224224
PORT=3001
225225
FRONTEND_URL=http://localhost:3000
226226
OPENAI_API_KEY=your-api-key-here
227227
228-
# Optional: Weights & Biases Weave for LLM tracing
228+
# Optional: Weights & Biases Weave for LLM tracing (local dev only)
229229
WANDB_API_KEY=your-wandb-api-key-here
230230
```
231231

232+
**Note**: When running on Runloop devboxes, API keys must be configured as Runloop secrets, not local environment variables. The `OPENAI_API_KEY` and `WANDB_API_KEY` secrets are automatically injected into devboxes from the Runloop secret store.
233+
232234
**Frontend (`packages/frontend/.env.local`):**
233235
```env
234236
NEXT_PUBLIC_AGENT_URL=http://localhost:3001
@@ -244,7 +246,14 @@ GITHUB_TOKEN=your-token-here # Required for private repos
244246

245247
The tax agent integrates with [Weights & Biases Weave](https://docs.wandb.ai/weave/) for comprehensive LLM call tracing and monitoring.
246248

247-
**Setup:**
249+
**Setup for Runloop Devboxes:**
250+
1. Get your W&B API key from https://wandb.ai/authorize
251+
2. Add `WANDB_API_KEY` to Runloop secrets:
252+
- Option A: Use the Runloop Settings page at https://platform.runloop.ai/settings
253+
- Option B: Run `pnpm step1_runloop_setup` - it will prompt you to add the secret
254+
3. When the agent runs on a devbox, Weave initializes automatically if the secret is present
255+
256+
**Setup for Local Development:**
248257
1. Get your W&B API key from https://wandb.ai/authorize
249258
2. Add `WANDB_API_KEY=your-key` to `packages/tax-processing/.env`
250259
3. Start the agent server - Weave initializes automatically
@@ -262,7 +271,7 @@ The tax agent integrates with [Weights & Biases Weave](https://docs.wandb.ai/wea
262271
- Explore traces, latency distributions, and token usage
263272

264273
**Configuration:**
265-
The CodexService automatically initializes Weave if `WANDB_API_KEY` is present. Look for:
274+
The CodexService automatically initializes Weave if `WANDB_API_KEY` is present in the environment (from Runloop secrets on devboxes, or from local `.env` file). Look for:
266275
- `[CodexService] Weave tracing initialized successfully` - Weave is active
267276
- `[CodexService] Weave tracing disabled: WANDB_API_KEY not set` - Running without Weave
268277

README.md

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ best. We can perform quick experiments to measure performance after making chang
6464

6565
c. Create a Secret for the OpenAI key you just generated in the [https://platform.runloop.ai/settings](settings) page. Name the secret name `OPENAI_API_KEY` and paste the key value from the OpenAI site.
6666

67-
d. Now configure your environment:
67+
d. (Optional) Create a Secret for W&B API key for Weave LLM tracing. Get your W&B API key from [https://wandb.ai/authorize](https://wandb.ai/authorize), then create a secret named `WANDB_API_KEY` in the [https://platform.runloop.ai/settings](settings) page. This enables Weave tracing on Runloop devboxes. Note: The `pnpm step1_runloop_setup` script will also prompt you for this.
68+
69+
e. Now configure your environment:
6870

6971
```bash
7072
export RUNLOOP_API_KEY=<your_runloop_api_key_here>
@@ -73,7 +75,7 @@ best. We can perform quick experiments to measure performance after making chang
7375

7476
Open the `.env` file and update values where prompted.
7577

76-
e. Launch the environment to test the setup:
78+
f. Launch the environment to test the setup:
7779

7880
```bash
7981
pnpm dev
@@ -85,27 +87,34 @@ best. We can perform quick experiments to measure performance after making chang
8587

8688
3. **(Optional) Enable Weave Tracing**
8789

88-
To track and monitor LLM calls with Weights & Biases Weave:
89-
90-
a. Get your W&B API key from [https://wandb.ai/authorize](https://wandb.ai/authorize)
91-
92-
b. Add the API key to `packages/tax-processing/.env`:
90+
The tax agent integrates with [Weights & Biases Weave](https://docs.wandb.ai/weave/) for comprehensive LLM call tracing and monitoring.
9391

94-
```bash
95-
WANDB_API_KEY=your-wandb-api-key-here
96-
```
92+
**For Local Development:**
93+
- Get your W&B API key from [https://wandb.ai/authorize](https://wandb.ai/authorize)
94+
- Add the API key to `packages/tax-processing/.env`:
95+
```bash
96+
WANDB_API_KEY=your-wandb-api-key-here
97+
```
98+
- When the agent server starts locally, you'll see:
99+
- Success: `[CodexService] Weave tracing initialized successfully`
100+
- Disabled: `[CodexService] Weave tracing disabled: WANDB_API_KEY not set`
97101
98-
c. When the agent server starts, you'll see:
99-
- Success: `[CodexService] Weave tracing initialized successfully`
100-
- Disabled: `[CodexService] Weave tracing disabled: WANDB_API_KEY not set`
102+
**For Runloop Devboxes:**
103+
- The `WANDB_API_KEY` must be configured as a Runloop secret (see step 2d above)
104+
- The `pnpm step1_runloop_setup` script will prompt you to add this secret
105+
- Weave automatically initializes when the agent runs on a devbox if the secret is present
101106
102-
d. View traces in your Weave dashboard at [https://wandb.ai/](https://wandb.ai/)
107+
**Viewing Traces:**
108+
- Navigate to [https://wandb.ai/](https://wandb.ai/)
109+
- Select project: `tax-preparation-agent`
110+
- Explore traces, latency distributions, and token usage
103111
104112
Weave automatically captures:
105113
- All OpenAI API calls made through the Codex SDK
106-
- Input prompts and output responses
107-
- Token usage and latency metrics
114+
- Complete input prompts and output responses
115+
- Token usage, latency, and cost metrics
108116
- Error traces and debugging information
117+
- Agent tool usage (taxctl commands)
109118
110119
**Note**: Weave is completely optional. The system works without it.
111120

packages/frontend/src/lib/tax-processing-service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,12 @@ export class TaxProcessingService {
8484
CODEX_SKIP_GIT_REPO_CHECK: 'true',
8585
RUNLOOP_DEVBOX: '1',
8686
},
87-
// wire in the OpenAI key from the Runloop secret store
88-
secrets: { OPENAI_API_KEY: 'OPENAI_API_KEY' },
87+
secrets: {
88+
// wire in the OpenAI key from the Runloop secret store
89+
OPENAI_API_KEY: 'OPENAI_API_KEY',
90+
// optionally wire in the WANDB key from the Runloop secret store
91+
// WANDB_API_KEY: 'WANDB_API_KEY',
92+
},
8993
});
9094

9195
logger.log(`Devbox created: ${this.devbox.id}`);

packages/scripts/src/harness-lib-async.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ export async function startBenchmarkRun(
297297
],
298298
secrets: {
299299
OPENAI_API_KEY: 'OPENAI_API_KEY',
300+
WANDB_API_KEY: 'WANDB_API_KEY',
300301
},
301302
} as any,
302303
});

packages/scripts/src/harness-lib.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ async function startScenarioRun(
119119
],
120120
secrets: {
121121
OPENAI_API_KEY: 'OPENAI_API_KEY',
122+
WANDB_API_KEY: 'WANDB_API_KEY',
122123
},
123124
} as any,
124125
});

packages/scripts/src/step1-runloop-setup.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,78 @@ async function installOpenaiKey(runloop: RunloopSDK): Promise<void> {
9999
}
100100
}
101101

102+
/**
103+
* Install the W&B API key in the Runloop secret store (optional).
104+
* This enables Weave LLM tracing on Runloop devboxes.
105+
*/
106+
async function installWandbKey(runloop: RunloopSDK): Promise<void> {
107+
try {
108+
// Check if secret already exists
109+
const secretsList = await runloop.api.secrets.list();
110+
const existingSecret = secretsList.secrets.find(
111+
(s) => s.name === 'WANDB_API_KEY'
112+
);
113+
114+
if (existingSecret) {
115+
console.log(
116+
' ✓ WANDB_API_KEY already exists in Runloop secret store (skipping)'
117+
);
118+
return;
119+
}
120+
121+
// Get default value from environment
122+
const defaultValue = process.env.WANDB_API_KEY;
123+
124+
// Construct prompt message
125+
let promptMessage =
126+
'🔑 WANDB_API_KEY not found in Runloop secret store.\n Optional: Provide your W&B API key for Weave LLM tracing';
127+
promptMessage += '\n (Get your key from https://wandb.ai/authorize)';
128+
129+
if (defaultValue) {
130+
const last4 = defaultValue.slice(-4);
131+
promptMessage += `\n (press Enter to use env var: ...${last4})`;
132+
}
133+
promptMessage += '\n (press Enter to skip): ';
134+
135+
// Prompt user interactively
136+
const rl = readline.createInterface({
137+
input: process.stdin,
138+
output: process.stdout,
139+
});
140+
141+
const userInput = await new Promise<string>((resolve) => {
142+
rl.question(promptMessage, (answer) => {
143+
rl.close();
144+
resolve(answer);
145+
});
146+
});
147+
148+
// Determine final value
149+
const finalValue = userInput.trim() || defaultValue;
150+
151+
if (!finalValue) {
152+
console.log(
153+
' ⏭️ Skipping WANDB_API_KEY setup (Weave tracing will be disabled)'
154+
);
155+
return;
156+
}
157+
158+
// Create secret in Runloop
159+
await runloop.api.secrets.create({
160+
name: 'WANDB_API_KEY',
161+
value: finalValue,
162+
});
163+
164+
console.log(' ✓ WANDB_API_KEY installed in Runloop secret store');
165+
} catch (error) {
166+
console.error(
167+
`⚠️ Warning: Could not manage WANDB_API_KEY secret: ${error instanceof Error ? error.message : error}`
168+
);
169+
console.log(' Continuing without Weave tracing...');
170+
// Don't exit - this is optional
171+
}
172+
}
173+
102174
async function main() {
103175
console.log('🚀 Starting Step 1 Runloop Setup...\n');
104176

@@ -145,6 +217,11 @@ async function main() {
145217
await installOpenaiKey(runloop);
146218
console.log('');
147219

220+
// Install W&B API key in secret store (optional)
221+
console.log('🔑 Checking for WANDB_API_KEY in Runloop secret store...\n');
222+
await installWandbKey(runloop);
223+
console.log('');
224+
148225
// Check if resources already exist on Runloop
149226
console.log('🔍 Checking for existing resources on Runloop...\n');
150227

packages/scripts/src/step1-start-devbox.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ async function main() {
7171
CODEX_SKIP_GIT_REPO_CHECK: 'true',
7272
RUNLOOP_DEVBOX: '1', // Tell the agent it's running on a devbox
7373
},
74-
secrets: { OPENAI_API_KEY: 'OPENAI_API_KEY' },
74+
secrets: {
75+
OPENAI_API_KEY: 'OPENAI_API_KEY',
76+
// optionally wire in the WANDB key from the Runloop secret store
77+
// WANDB_API_KEY: 'WANDB_API_KEY',
78+
},
7579
launch_parameters: {
7680
keep_alive_time_seconds: 86400,
7781
// after_idle: { idle_time_seconds: 3600, on_idle: "suspend" } // exclusive with keep_alive_time_seconds

packages/scripts/src/step1-start-prebuild-devbox.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ async function main() {
7070
CODEX_SKIP_GIT_REPO_CHECK: 'true',
7171
RUNLOOP_DEVBOX: '1', // Tell the agent it's running on a devbox
7272
},
73-
secrets: { OPENAI_API_KEY: 'OPENAI_API_KEY' },
73+
secrets: {
74+
OPENAI_API_KEY: 'OPENAI_API_KEY',
75+
// optionally wire in the WANDB key from the Runloop secret store
76+
// WANDB_API_KEY: 'WANDB_API_KEY',
77+
},
7478
launch_parameters: {
7579
keep_alive_time_seconds: 86400,
7680
},

packages/scripts/src/step3-generate-expected-outputs.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ async function generateExpectedOutput(
4949
CODEX_SKIP_GIT_REPO_CHECK: 'true',
5050
RUNLOOP_DEVBOX: '1',
5151
},
52-
secrets: { OPENAI_API_KEY: 'OPENAI_API_KEY' },
52+
secrets: {
53+
OPENAI_API_KEY: 'OPENAI_API_KEY',
54+
// By step 3, tracing is beneficial so we'll require the WANDB key
55+
WANDB_API_KEY: 'WANDB_API_KEY',
56+
},
5357
});
5458

5559
try {

0 commit comments

Comments
 (0)