Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions weave/custom-agents-quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ async function runTurn(history: any[], userMessage: string): Promise<string | nu
const turn = weave.startTurn({ model: MODEL });
try {
// LLM call 1: the model might decide to use a tool.
const llm1 = weave.startLLM({ model: MODEL, providerName: 'openai' });
const llm1 = turn.startLLM({ model: MODEL, providerName: 'openai' });
let msg;
try {
const resp = await openaiClient.chat.completions.create({
Expand All @@ -274,7 +274,7 @@ async function runTurn(history: any[], userMessage: string): Promise<string | nu
// Execute each requested tool call.
for (const tc of msg.tool_calls) {
if (tc.type !== 'function') continue;
const tool = weave.startTool({
const tool = turn.startTool({
name: tc.function.name,
args: tc.function.arguments,
toolCallId: tc.id,
Expand All @@ -289,7 +289,7 @@ async function runTurn(history: any[], userMessage: string): Promise<string | nu
}

// LLM call 2: synthesize the final answer.
const llm2 = weave.startLLM({ model: MODEL, providerName: 'openai' });
const llm2 = turn.startLLM({ model: MODEL, providerName: 'openai' });
try {
const resp = await openaiClient.chat.completions.create({
model: MODEL,
Expand Down
2 changes: 1 addition & 1 deletion weave/guides/tracking/trace-agents-attributes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import * as weave from 'weave';
await weave.init('[TEAM-NAME]/[PROJECT-NAME]');

const conversation = weave.startConversation({ agentName: 'my-agent' });
const turn = weave.startTurn({ agentName: 'my-agent' });
const turn = conversation.startTurn({ agentName: 'my-agent' });

// Stamp attributes on this turn span
turn.setAttributes({ user_id: '12345', tenant: 'acme', env: 'production' });
Expand Down
12 changes: 6 additions & 6 deletions weave/guides/tracking/trace-agents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,15 @@ try {
const turn = conversation.startTurn({ agentName: 'weather-bot' });
try {
// First LLM call: returns a tool call.
const llm = weave.startLLM({ model: 'gpt-4o', providerName: 'openai' });
const llm = turn.startLLM({ model: 'gpt-4o', providerName: 'openai' });
try {
llm.inputMessages = [{ role: 'user', content: 'What is the weather?' }];
llm.think('User wants weather data, I should call get_weather.');
llm.output('Let me check the weather for you.');
llm.usage = { inputTokens: 100, outputTokens: 20 };

// Tool call: child of the LLM call that requested it.
const tool = weave.startTool({ name: 'get_weather', args: '{"city":"Tokyo"}' });
const tool = llm.startTool({ name: 'get_weather', args: '{"city":"Tokyo"}' });
try {
tool.result = await getWeatherApi('Tokyo'); // Returns "24°C, sunny".
} finally {
Expand All @@ -409,7 +409,7 @@ try {
}

// Second LLM call: synthesizes the final answer.
const llm2 = weave.startLLM({ model: 'gpt-4o', providerName: 'openai' });
const llm2 = turn.startLLM({ model: 'gpt-4o', providerName: 'openai' });
try {
llm2.inputMessages = [{ role: 'user', content: 'What is the weather?' }];
llm2.output('It is 24°C and sunny in Tokyo today.');
Expand Down Expand Up @@ -467,18 +467,18 @@ conversation.end()
const conversation = weave.startConversation({ agentName: 'weather-bot' });
const turn = conversation.startTurn({ agentName: 'weather-bot' });

const llm = weave.startLLM({ model: 'gpt-4o', providerName: 'openai' });
const llm = turn.startLLM({ model: 'gpt-4o', providerName: 'openai' });
llm.inputMessages = [{ role: 'user', content: 'What is the weather?' }];
llm.output('Let me check.');
llm.usage = { inputTokens: 100, outputTokens: 20 };

const tool = weave.startTool({ name: 'get_weather', args: '{"city": "Tokyo"}' });
const tool = llm.startTool({ name: 'get_weather', args: '{"city": "Tokyo"}' });
tool.result = '24°C, sunny';
tool.end(); // end() is idempotent: safe to call more than once.

llm.end();

const llm2 = weave.startLLM({ model: 'gpt-4o', providerName: 'openai' });
const llm2 = turn.startLLM({ model: 'gpt-4o', providerName: 'openai' });
llm2.output('It is 24°C and sunny in Tokyo.');
llm2.usage = { inputTokens: 150, outputTokens: 30 };
llm2.end();
Expand Down
Loading