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
63 changes: 62 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/botonic-plugin-ai-agents/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@botonic/core": "^0.51.1",
"@openai/agents": "^0.10.1",
"axios": "^1.15.2",
"langsmith": "^0.7.15",
"openai": "^6.36.0",
"uuid": "^10.0.0",
"zod": "^4.3.6"
Expand Down
4 changes: 4 additions & 0 deletions packages/botonic-plugin-ai-agents/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ export const MAX_MEMORY_LENGTH = 25

export const DEFAULT_TIMEOUT_16_SECONDS = 16000
export const DEFAULT_MAX_RETRIES = 2

export const LANGSMITH_ENDPOINT = process.env.LANGSMITH_ENDPOINT
export const LANGSMITH_API_KEY = process.env.LANGSMITH_API_KEY
export const LANGSMITH_WORKSPACE_ID = process.env.LANGSMITH_WORKSPACE_ID
4 changes: 2 additions & 2 deletions packages/botonic-plugin-ai-agents/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
type ReasoningEffort,
type ResolvedPlugins,
} from '@botonic/core'
import { handoff, setTracingDisabled, tool } from '@openai/agents'
import { handoff, tool } from '@openai/agents'
import { v7 as uuidv7 } from 'uuid'
import type { ZodObject } from 'zod'
import { RouterAgent, SpecialistAgent } from './agents'
Expand Down Expand Up @@ -54,7 +54,7 @@ export default class BotonicPluginAiAgents<
this.maxRetries = options?.maxRetries ?? DEFAULT_MAX_RETRIES
this.logger = createDebugLogger(options?.enableDebug ?? false)
this.localStorageKey = options?.localStorageKey ?? 'botonicState'
setTracingDisabled(true)
// setTracingDisabled(true)

this.logger.logInitialConfig({
messageHistoryApiVersion: 'v2',
Expand Down
2 changes: 2 additions & 0 deletions packages/botonic-plugin-ai-agents/src/llm-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
LLM_PROVIDERS,
type LLMProviderType,
} from './constants'
import { setTraceProcessor } from './trace-processor'

export interface LLMConfigParams {
maxRetries: number
Expand Down Expand Up @@ -60,6 +61,7 @@ export class LLMConfig {

private getModelProvider(): ModelProvider {
const client = this.getClient()
setTraceProcessor(client)
return new OpenAIProvider({
openAIClient: client,
useResponses: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export abstract class BaseRunner<

try {
const runner = new Runner({
tracingDisabled: true,
tracingDisabled: false,
})
const result = (await runner.run(this.agent, messages, {
context,
Expand Down
33 changes: 33 additions & 0 deletions packages/botonic-plugin-ai-agents/src/trace-processor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { setDefaultOpenAIClient, setTraceProcessors } from '@openai/agents'
import { Client } from 'langsmith'
import { OpenAIAgentsTracingProcessor } from 'langsmith/wrappers/openai_agents'
import type OpenAI from 'openai'
import type { AzureOpenAI } from 'openai'
import {
LANGSMITH_API_KEY,
LANGSMITH_ENDPOINT,
LANGSMITH_WORKSPACE_ID,
} from './constants'

export function setTraceProcessor(litellmClient: OpenAI | AzureOpenAI) {
setDefaultOpenAIClient(litellmClient)

const langsmithClient = new Client({
apiKey: LANGSMITH_API_KEY,
apiUrl: LANGSMITH_ENDPOINT,
workspaceId: LANGSMITH_WORKSPACE_ID,
})

const langsmithProcessor = new OpenAIAgentsTracingProcessor({
client: langsmithClient,
projectName: 'ai-agents-bots',
name: 'AI Agents workflow',
tags: ['openai-agents', 'litellm'],
metadata: {
environment: process.env.NODE_ENV ?? 'development',
gateway: 'litellm',
},
})

setTraceProcessors([langsmithProcessor])
}
Loading