@osohq/langchain 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Support. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2024 Oso Security, Inc.
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,271 @@
1
+ # @osohq/langchain
2
+
3
+ Oso observability integration for LangChain agents.
4
+
5
+ Callback handler that automatically captures and sends all LangChain agent events to Oso's observability platform for monitoring, debugging, and security analysis.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @osohq/langchain
11
+ ```
12
+
13
+ Or with yarn:
14
+
15
+ ```bash
16
+ yarn add @osohq/langchain
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ ```typescript
22
+ import { OsoObservabilityCallback } from "@osohq/langchain";
23
+ import { createOpenAIToolsAgent, AgentExecutor } from "langchain/agents";
24
+ import { ChatOpenAI } from "@langchain/openai";
25
+
26
+ // Create the callback (reads OSO_AUTH_TOKEN from environment)
27
+ const callback = new OsoObservabilityCallback({
28
+ agentId: "my-support-agent",
29
+ });
30
+
31
+ // Add to your agent
32
+ const llm = new ChatOpenAI({ model: "gpt-4" });
33
+ const agent = await createOpenAIToolsAgent({ llm, tools, prompt });
34
+ const agentExecutor = new AgentExecutor({
35
+ agent,
36
+ tools,
37
+ callbacks: [callback],
38
+ });
39
+
40
+ // Use your agent - all events are automatically captured
41
+ const result = await agentExecutor.invoke({
42
+ input: "Hello, how can I help?",
43
+ });
44
+
45
+ // Clean up
46
+ await callback.close();
47
+ ```
48
+
49
+ ## Configuration
50
+
51
+ ### Environment Variables
52
+
53
+ Set these in your environment or `.env` file:
54
+
55
+ ```bash
56
+ # Required: Your Oso authentication token
57
+ OSO_AUTH_TOKEN=your-token-here
58
+
59
+ # Optional: Custom Oso endpoint (defaults to https://cloud.osohq.com/api/events)
60
+ OSO_ENDPOINT=https://cloud.osohq.com/api/events
61
+
62
+ # Optional: Enable/disable observability (defaults to true)
63
+ OSO_OBSERVABILITY_ENABLED=true
64
+ ```
65
+
66
+ ### Constructor Parameters
67
+
68
+ ```typescript
69
+ new OsoObservabilityCallback({
70
+ endpoint: "https://cloud.osohq.com/api/events", // Oso endpoint URL
71
+ authToken: "your-token", // Oso auth token
72
+ enabled: true, // Enable/disable sending events
73
+ sessionId: "unique-session-id", // Group related conversations
74
+ metadata: { userId: "123", env: "prod" }, // Custom metadata for all events
75
+ agentId: "my-agent", // Agent identifier
76
+ });
77
+ ```
78
+
79
+ All parameters are optional and fall back to environment variables or defaults.
80
+
81
+ ## What Gets Captured
82
+
83
+ The callback automatically captures all LangChain events:
84
+
85
+ ### LLM Events
86
+
87
+ - Model name and configuration
88
+ - Prompts sent to the LLM
89
+ - Generated responses
90
+ - Token usage (prompt, completion, total)
91
+ - Errors and failures
92
+
93
+ ### Tool Events
94
+
95
+ - Tool name and description
96
+ - Input parameters
97
+ - Output/results
98
+ - Execution duration (milliseconds)
99
+ - Errors and stack traces
100
+
101
+ ### Agent Events
102
+
103
+ - Agent reasoning and thought process
104
+ - Tool selection decisions
105
+ - Tool input parameters
106
+ - Final outputs
107
+ - Complete execution flow
108
+
109
+ ### Chain Events
110
+
111
+ - Chain type and name
112
+ - Input parameters
113
+ - Output values
114
+ - Nested chain execution
115
+
116
+ ### Execution Summary
117
+
118
+ At the end of each agent execution, a summary event is sent with:
119
+
120
+ - Total execution duration
121
+ - Number of LLM calls, tool calls, and agent steps
122
+ - Total token usage
123
+ - Error count
124
+ - Complete execution trace
125
+
126
+ ## Event Structure
127
+
128
+ Every event sent to Oso has this structure:
129
+
130
+ ```json
131
+ {
132
+ "event_type": "tool.completed",
133
+ "execution_id": "unique-execution-id",
134
+ "session_id": "conversation-session-id",
135
+ "timestamp": "2024-02-15T10:30:45.123Z",
136
+ "agent_id": "my-agent",
137
+ "data": {
138
+ /* event-specific data */
139
+ },
140
+ "metadata": {
141
+ /* your custom metadata */
142
+ }
143
+ }
144
+ ```
145
+
146
+ ### Event Types
147
+
148
+ - `llm.started` / `llm.completed` / `llm.error`
149
+ - `tool.started` / `tool.completed` / `tool.error`
150
+ - `agent.action` / `agent.finished`
151
+ - `chain.started` / `chain.completed` / `chain.error`
152
+ - `execution.summary` - Final summary with all accumulated data
153
+
154
+ ## Error Handling
155
+
156
+ The callback is designed to fail gracefully:
157
+
158
+ - Network errors or timeouts won't crash your agent
159
+ - Failed event sends are logged but don't interrupt execution
160
+ - Comprehensive error logging for debugging
161
+
162
+ ## Logging
163
+
164
+ The callback uses Node.js console logging. You can configure it in your application or use a custom logger:
165
+
166
+ ```typescript
167
+ // Set NODE_DEBUG environment variable to see debug logs
168
+ process.env.NODE_DEBUG = "langchain-oso";
169
+ ```
170
+
171
+ ## Examples
172
+
173
+ ### Basic Agent with Tools
174
+
175
+ ```typescript
176
+ import { OsoObservabilityCallback } from "@osohq/langchain";
177
+ import { createOpenAIToolsAgent, AgentExecutor } from "langchain/agents";
178
+ import { ChatOpenAI } from "@langchain/openai";
179
+ import { tool } from "@langchain/core/tools";
180
+
181
+ const searchOrders = tool(
182
+ async ({ customerId }: { customerId: string }) => {
183
+ return `Orders for ${customerId}: ORD001, ORD002`;
184
+ },
185
+ {
186
+ name: "search_orders",
187
+ description: "Search for customer orders.",
188
+ schema: z.object({
189
+ customerId: z.string().describe("The customer ID"),
190
+ }),
191
+ }
192
+ );
193
+
194
+ async function main() {
195
+ const callback = new OsoObservabilityCallback({ agentId: "support-agent" });
196
+
197
+ const llm = new ChatOpenAI({ model: "gpt-4o-mini" });
198
+ const tools = [searchOrders];
199
+
200
+ const agent = await createOpenAIToolsAgent({ llm, tools, prompt });
201
+ const agentExecutor = new AgentExecutor({
202
+ agent,
203
+ tools,
204
+ callbacks: [callback],
205
+ });
206
+
207
+ const result = await agentExecutor.invoke({
208
+ input: "Find orders for customer CUST001",
209
+ });
210
+
211
+ console.log(result.output);
212
+
213
+ await callback.close();
214
+ }
215
+ ```
216
+
217
+ ### With Custom Metadata
218
+
219
+ ```typescript
220
+ const callback = new OsoObservabilityCallback({
221
+ agentId: "support-agent",
222
+ sessionId: "user-session-123",
223
+ metadata: {
224
+ userId: "user-456",
225
+ environment: "production",
226
+ version: "1.2.3",
227
+ },
228
+ });
229
+ ```
230
+
231
+ ### Multiple Agents in Same Session
232
+
233
+ ```typescript
234
+ import { randomUUID } from "crypto";
235
+
236
+ const sessionId = randomUUID();
237
+
238
+ // Agent 1
239
+ const callback1 = new OsoObservabilityCallback({
240
+ agentId: "agent-1",
241
+ sessionId,
242
+ });
243
+ const result1 = await agent1Executor.invoke({ input: "..." });
244
+ await callback1.close();
245
+
246
+ // Agent 2 - same session
247
+ const callback2 = new OsoObservabilityCallback({
248
+ agentId: "agent-2",
249
+ sessionId,
250
+ });
251
+ const result2 = await agent2Executor.invoke({ input: "..." });
252
+ await callback2.close();
253
+ ```
254
+
255
+ ## TypeScript Support
256
+
257
+ This package is written in TypeScript and includes full type definitions. All types are exported for your convenience.
258
+
259
+ ## Requirements
260
+
261
+ - Node.js 16.0.0 or higher
262
+ - @langchain/core >= 0.1.0
263
+
264
+ ## License
265
+
266
+ Apache License 2.0
267
+
268
+ ## Support
269
+
270
+ - Documentation: https://www.osohq.com/docs
271
+ - Website: https://www.osohq.com
@@ -0,0 +1,79 @@
1
+ /**
2
+ * LangChain callback handler for Oso observability integration.
3
+ *
4
+ * Example usage:
5
+ * import { OsoObservabilityCallback } from '@osohq/langchain';
6
+ *
7
+ * const callback = new OsoObservabilityCallback({
8
+ * authToken: "your-oso-auth-token",
9
+ * agentId: "my-support-agent"
10
+ * });
11
+ *
12
+ * const agent = createAgent({ callbacks: [callback] });
13
+ * const result = await agent.invoke({ input: "Hello" });
14
+ * await callback.close();
15
+ */
16
+ import { BaseCallbackHandler } from "@langchain/core/callbacks/base";
17
+ import type { AgentAction, AgentFinish } from "@langchain/core/agents";
18
+ import type { LLMResult } from "@langchain/core/outputs";
19
+ import type { Serialized } from "@langchain/core/load/serializable";
20
+ interface OsoObservabilityCallbackConfig {
21
+ /** Oso observability endpoint URL (default: OSO_ENDPOINT env var or https://cloud.osohq.com/api/events) */
22
+ endpoint?: string;
23
+ /** Oso authentication token (default: OSO_AUTH_TOKEN env var) */
24
+ authToken?: string;
25
+ /** Whether to send events (default: OSO_OBSERVABILITY_ENABLED env var or true) */
26
+ enabled?: boolean;
27
+ /** Session ID to group related conversations (default: auto-generated UUID) */
28
+ sessionId?: string;
29
+ /** Additional metadata to attach to all events */
30
+ metadata?: Record<string, any>;
31
+ /** Agent identifier for tracking (default: "default-agent") */
32
+ agentId?: string;
33
+ }
34
+ /**
35
+ * LangChain callback handler that sends agent events to Oso observability.
36
+ *
37
+ * Automatically captures:
38
+ * - LLM calls (model, prompts, responses, token usage)
39
+ * - Tool executions (name, inputs, outputs, duration, errors)
40
+ * - Agent reasoning (decisions, thoughts, intermediate steps)
41
+ * - Chain executions (starts, ends, inputs, outputs)
42
+ * - Errors at any stage
43
+ */
44
+ export declare class OsoObservabilityCallback extends BaseCallbackHandler {
45
+ name: string;
46
+ private endpoint;
47
+ private authToken?;
48
+ private enabled;
49
+ private sessionId;
50
+ private metadata;
51
+ private agentId;
52
+ private executionId;
53
+ private executionStartTime;
54
+ private toolStartTimes;
55
+ private llmCalls;
56
+ private toolCalls;
57
+ private agentSteps;
58
+ private errors;
59
+ constructor(config?: OsoObservabilityCallbackConfig);
60
+ handleLLMStart(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: Record<string, any>, tags?: string[], metadata?: Record<string, any>): Promise<void>;
61
+ handleLLMEnd(output: LLMResult, runId: string, parentRunId?: string): Promise<void>;
62
+ handleLLMError(error: Error, runId: string, parentRunId?: string): Promise<void>;
63
+ handleToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, any>): Promise<void>;
64
+ handleToolEnd(output: string, runId: string, parentRunId?: string): Promise<void>;
65
+ handleToolError(error: Error, runId: string, parentRunId?: string): Promise<void>;
66
+ handleAgentAction(action: AgentAction, runId: string, parentRunId?: string): Promise<void>;
67
+ handleAgentEnd(action: AgentFinish, runId: string, parentRunId?: string): Promise<void>;
68
+ handleChainStart(chain: Serialized, inputs: Record<string, any>, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, any>): Promise<void>;
69
+ handleChainEnd(outputs: Record<string, any>, runId: string, parentRunId?: string): Promise<void>;
70
+ handleChainError(error: Error, runId: string, parentRunId?: string): Promise<void>;
71
+ private sendEvent;
72
+ private sendExecutionSummary;
73
+ /**
74
+ * Clean up resources. Call this when you're done using the callback.
75
+ */
76
+ close(): Promise<void>;
77
+ }
78
+ export {};
79
+ //# sourceMappingURL=callbacks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callbacks.d.ts","sourceRoot":"","sources":["../src/callbacks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAIpE,UAAU,8BAA8B;IACtC,2GAA2G;IAC3G,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kFAAkF;IAClF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,+EAA+E;IAC/E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/B,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAkCD;;;;;;;;;GASG;AACH,qBAAa,wBAAyB,SAAQ,mBAAmB;IAC/D,IAAI,SAA8B;IAElC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,OAAO,CAAS;IAExB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,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,iBAAiB,CACrB,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC;IAYV,cAAc,CAClB,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC;IAYV,gBAAgB,CACpB,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,KAAK,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,MAAM,EACpB,IAAI,CAAC,EAAE,MAAM,EAAE,EACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC7B,OAAO,CAAC,IAAI,CAAC;IASV,cAAc,CAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC5B,KAAK,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC;IAIV,gBAAgB,CACpB,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC;YAWF,SAAS;YAoDT,oBAAoB;IA0BlC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAI7B"}
@@ -0,0 +1,297 @@
1
+ "use strict";
2
+ /**
3
+ * LangChain callback handler for Oso observability integration.
4
+ *
5
+ * Example usage:
6
+ * import { OsoObservabilityCallback } from '@osohq/langchain';
7
+ *
8
+ * const callback = new OsoObservabilityCallback({
9
+ * authToken: "your-oso-auth-token",
10
+ * agentId: "my-support-agent"
11
+ * });
12
+ *
13
+ * const agent = createAgent({ callbacks: [callback] });
14
+ * const result = await agent.invoke({ input: "Hello" });
15
+ * await callback.close();
16
+ */
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __importDefault = (this && this.__importDefault) || function (mod) {
27
+ return (mod && mod.__esModule) ? mod : { "default": mod };
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.OsoObservabilityCallback = void 0;
31
+ const base_1 = require("@langchain/core/callbacks/base");
32
+ const cross_fetch_1 = __importDefault(require("cross-fetch"));
33
+ const crypto_1 = require("crypto");
34
+ /**
35
+ * LangChain callback handler that sends agent events to Oso observability.
36
+ *
37
+ * Automatically captures:
38
+ * - LLM calls (model, prompts, responses, token usage)
39
+ * - Tool executions (name, inputs, outputs, duration, errors)
40
+ * - Agent reasoning (decisions, thoughts, intermediate steps)
41
+ * - Chain executions (starts, ends, inputs, outputs)
42
+ * - Errors at any stage
43
+ */
44
+ class OsoObservabilityCallback extends base_1.BaseCallbackHandler {
45
+ constructor(config = {}) {
46
+ super();
47
+ this.name = "OsoObservabilityCallback";
48
+ // Accumulate data for summary event
49
+ this.llmCalls = [];
50
+ this.toolCalls = [];
51
+ this.agentSteps = [];
52
+ this.errors = [];
53
+ this.endpoint =
54
+ config.endpoint ||
55
+ process.env.OSO_ENDPOINT ||
56
+ "https://cloud.osohq.com/api/events";
57
+ this.authToken = config.authToken || process.env.OSO_AUTH_TOKEN;
58
+ this.enabled =
59
+ config.enabled !== undefined
60
+ ? config.enabled
61
+ : (process.env.OSO_OBSERVABILITY_ENABLED || "true").toLowerCase() ===
62
+ "true";
63
+ this.sessionId = config.sessionId || (0, crypto_1.randomUUID)();
64
+ this.metadata = config.metadata || {};
65
+ this.agentId = config.agentId || "default-agent";
66
+ this.executionId = (0, crypto_1.randomUUID)();
67
+ this.executionStartTime = Date.now();
68
+ this.toolStartTimes = new Map();
69
+ console.debug(`OsoObservabilityCallback initialized: endpoint=${this.endpoint}, ` +
70
+ `agentId=${this.agentId}, sessionId=${this.sessionId}, enabled=${this.enabled}`);
71
+ }
72
+ // LLM callbacks
73
+ handleLLMStart(llm, prompts, runId, parentRunId, extraParams, tags, metadata) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ var _a;
76
+ const modelName = (llm === null || llm === void 0 ? void 0 : llm.name) || ((_a = llm === null || llm === void 0 ? void 0 : llm.id) === null || _a === void 0 ? void 0 : _a[llm.id.length - 1]) || "unknown";
77
+ yield this.sendEvent("llm.started", {
78
+ model: modelName,
79
+ prompts,
80
+ num_prompts: prompts.length,
81
+ });
82
+ });
83
+ }
84
+ handleLLMEnd(output, runId, parentRunId) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ try {
87
+ const llmOutput = output.llmOutput || {};
88
+ const tokenUsage = llmOutput.tokenUsage || {};
89
+ const generations = [];
90
+ if (output.generations) {
91
+ for (const genList of output.generations) {
92
+ for (const gen of genList) {
93
+ generations.push({
94
+ text: gen.text || String(gen),
95
+ metadata: gen.generationInfo || {},
96
+ });
97
+ }
98
+ }
99
+ }
100
+ const callData = {
101
+ model: llmOutput.modelName || "unknown",
102
+ generations,
103
+ token_usage: {
104
+ prompt_tokens: tokenUsage.promptTokens || 0,
105
+ completion_tokens: tokenUsage.completionTokens || 0,
106
+ total_tokens: tokenUsage.totalTokens || 0,
107
+ },
108
+ };
109
+ this.llmCalls.push(callData);
110
+ yield this.sendEvent("llm.completed", callData);
111
+ }
112
+ catch (error) {
113
+ console.error(`Error in handleLLMEnd: ${error}`);
114
+ yield this.sendEvent("llm.error", { error: String(error) });
115
+ }
116
+ });
117
+ }
118
+ handleLLMError(error, runId, parentRunId) {
119
+ return __awaiter(this, void 0, void 0, function* () {
120
+ const errorData = {
121
+ error_type: error.constructor.name,
122
+ error_message: error.message,
123
+ };
124
+ this.errors.push(Object.assign({ type: "llm_error" }, errorData));
125
+ yield this.sendEvent("llm.error", errorData);
126
+ });
127
+ }
128
+ // Tool callbacks
129
+ handleToolStart(tool, input, runId, parentRunId, tags, metadata) {
130
+ return __awaiter(this, void 0, void 0, function* () {
131
+ const toolName = (tool === null || tool === void 0 ? void 0 : tool.name) || "unknown";
132
+ const toolDescription = (tool === null || tool === void 0 ? void 0 : tool.description) || "";
133
+ this.toolStartTimes.set(runId, Date.now());
134
+ yield this.sendEvent("tool.started", {
135
+ tool_name: toolName,
136
+ tool_description: toolDescription,
137
+ input,
138
+ run_id: runId,
139
+ });
140
+ });
141
+ }
142
+ handleToolEnd(output, runId, parentRunId) {
143
+ return __awaiter(this, void 0, void 0, function* () {
144
+ const startTime = this.toolStartTimes.get(runId);
145
+ const durationMs = startTime ? Date.now() - startTime : null;
146
+ const toolData = {
147
+ output,
148
+ duration_ms: durationMs,
149
+ run_id: runId,
150
+ };
151
+ this.toolCalls.push(toolData);
152
+ yield this.sendEvent("tool.completed", toolData);
153
+ this.toolStartTimes.delete(runId);
154
+ });
155
+ }
156
+ handleToolError(error, runId, parentRunId) {
157
+ return __awaiter(this, void 0, void 0, function* () {
158
+ const startTime = this.toolStartTimes.get(runId);
159
+ const durationMs = startTime ? Date.now() - startTime : null;
160
+ const errorData = {
161
+ error_type: error.constructor.name,
162
+ error_message: error.message,
163
+ duration_ms: durationMs,
164
+ run_id: runId,
165
+ };
166
+ this.errors.push(Object.assign({ type: "tool_error" }, errorData));
167
+ yield this.sendEvent("tool.error", errorData);
168
+ this.toolStartTimes.delete(runId);
169
+ });
170
+ }
171
+ // Agent callbacks
172
+ handleAgentAction(action, runId, parentRunId) {
173
+ return __awaiter(this, void 0, void 0, function* () {
174
+ const stepData = {
175
+ step_type: "action",
176
+ tool: action.tool,
177
+ tool_input: action.toolInput,
178
+ reasoning: action.log,
179
+ };
180
+ this.agentSteps.push(stepData);
181
+ yield this.sendEvent("agent.action", stepData);
182
+ });
183
+ }
184
+ handleAgentEnd(action, runId, parentRunId) {
185
+ return __awaiter(this, void 0, void 0, function* () {
186
+ const finishData = {
187
+ return_values: action.returnValues,
188
+ final_reasoning: action.log || null,
189
+ };
190
+ yield this.sendEvent("agent.finished", finishData);
191
+ yield this.sendExecutionSummary();
192
+ });
193
+ }
194
+ // Chain callbacks
195
+ handleChainStart(chain, inputs, runId, parentRunId, tags, metadata) {
196
+ return __awaiter(this, void 0, void 0, function* () {
197
+ var _a;
198
+ const chainName = (chain === null || chain === void 0 ? void 0 : chain.name) || ((_a = chain === null || chain === void 0 ? void 0 : chain.id) === null || _a === void 0 ? void 0 : _a[chain.id.length - 1]) || "unknown";
199
+ yield this.sendEvent("chain.started", {
200
+ chain_name: chainName,
201
+ inputs,
202
+ });
203
+ });
204
+ }
205
+ handleChainEnd(outputs, runId, parentRunId) {
206
+ return __awaiter(this, void 0, void 0, function* () {
207
+ yield this.sendEvent("chain.completed", { outputs });
208
+ });
209
+ }
210
+ handleChainError(error, runId, parentRunId) {
211
+ return __awaiter(this, void 0, void 0, function* () {
212
+ const errorData = {
213
+ error_type: error.constructor.name,
214
+ error_message: error.message,
215
+ };
216
+ this.errors.push(Object.assign({ type: "chain_error" }, errorData));
217
+ yield this.sendEvent("chain.error", errorData);
218
+ });
219
+ }
220
+ // Internal methods
221
+ sendEvent(eventType, data) {
222
+ return __awaiter(this, void 0, void 0, function* () {
223
+ if (!this.enabled) {
224
+ return;
225
+ }
226
+ try {
227
+ const payload = {
228
+ event_type: eventType,
229
+ execution_id: this.executionId,
230
+ session_id: this.sessionId,
231
+ timestamp: new Date().toISOString().replace("+00:00", "Z"),
232
+ data,
233
+ metadata: this.metadata,
234
+ agent_id: this.agentId,
235
+ };
236
+ console.debug(`Sending event: ${eventType}`);
237
+ const headers = {
238
+ "Content-Type": "application/json",
239
+ };
240
+ if (this.authToken) {
241
+ headers["Authorization"] = `Bearer ${this.authToken}`;
242
+ }
243
+ const response = yield (0, cross_fetch_1.default)(this.endpoint, {
244
+ method: "POST",
245
+ headers,
246
+ body: JSON.stringify(payload),
247
+ });
248
+ if (![200, 201, 202].includes(response.status)) {
249
+ console.warn(`Oso backend returned ${response.status} for event ${eventType}`);
250
+ }
251
+ else {
252
+ console.debug(`Event ${eventType} sent successfully`);
253
+ }
254
+ }
255
+ catch (error) {
256
+ if (error instanceof Error) {
257
+ console.warn(`Error sending event ${eventType}: ${error.constructor.name}: ${error.message}`);
258
+ }
259
+ else {
260
+ console.error(`Error sending event ${eventType}:`, error);
261
+ }
262
+ }
263
+ });
264
+ }
265
+ sendExecutionSummary() {
266
+ return __awaiter(this, void 0, void 0, function* () {
267
+ const durationMs = Date.now() - this.executionStartTime;
268
+ const totalTokens = this.llmCalls.reduce((sum, call) => sum + (call.token_usage.total_tokens || 0), 0);
269
+ const summary = {
270
+ execution_id: this.executionId,
271
+ session_id: this.sessionId,
272
+ duration_ms: durationMs,
273
+ llm_calls_count: this.llmCalls.length,
274
+ tool_calls_count: this.toolCalls.length,
275
+ agent_steps_count: this.agentSteps.length,
276
+ errors_count: this.errors.length,
277
+ total_tokens: totalTokens,
278
+ llm_calls: this.llmCalls,
279
+ tool_calls: this.toolCalls,
280
+ agent_steps: this.agentSteps,
281
+ errors: this.errors,
282
+ };
283
+ yield this.sendEvent("execution.summary", summary);
284
+ });
285
+ }
286
+ /**
287
+ * Clean up resources. Call this when you're done using the callback.
288
+ */
289
+ close() {
290
+ return __awaiter(this, void 0, void 0, function* () {
291
+ console.debug("OsoObservabilityCallback closed");
292
+ // No persistent connections to close in this implementation
293
+ });
294
+ }
295
+ }
296
+ exports.OsoObservabilityCallback = OsoObservabilityCallback;
297
+ //# sourceMappingURL=callbacks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callbacks.js","sourceRoot":"","sources":["../src/callbacks.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;AAEH,y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AEF,MAAM,OAAO,GAAG;gBACd,YAAY,EAAE,IAAI,CAAC,WAAW;gBAC9B,UAAU,EAAE,IAAI,CAAC,SAAS;gBAC1B,WAAW,EAAE,UAAU;gBACvB,eAAe,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM;gBACrC,gBAAgB,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM;gBACvC,iBAAiB,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM;gBACzC,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;gBAChC,YAAY,EAAE,WAAW;gBACzB,SAAS,EAAE,IAAI,CAAC,QAAQ;gBACxB,UAAU,EAAE,IAAI,CAAC,SAAS;gBAC1B,WAAW,EAAE,IAAI,CAAC,UAAU;gBAC5B,MAAM,EAAE,IAAI,CAAC,MAAM;aACpB,CAAC;YAEF,MAAM,IAAI,CAAC,SAAS,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;QACrD,CAAC;KAAA;IAED;;OAEG;IACG,KAAK;;YACT,OAAO,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;YACjD,4DAA4D;QAC9D,CAAC;KAAA;CACF;AAtVD,4DAsVC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Oso observability integration for LangChain.
3
+ */
4
+ export { OsoObservabilityCallback } from "./callbacks";
5
+ export { VERSION } from "./version";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ /**
3
+ * Oso observability integration for LangChain.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.VERSION = exports.OsoObservabilityCallback = void 0;
7
+ var callbacks_1 = require("./callbacks");
8
+ Object.defineProperty(exports, "OsoObservabilityCallback", { enumerable: true, get: function () { return callbacks_1.OsoObservabilityCallback; } });
9
+ var version_1 = require("./version");
10
+ Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_1.VERSION; } });
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,yCAAuD;AAA9C,qHAAA,wBAAwB,OAAA;AACjC,qCAAoC;AAA3B,kGAAA,OAAO,OAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const VERSION = "0.1.0";
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,UAAU,CAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VERSION = void 0;
4
+ exports.VERSION = "0.1.0";
5
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,OAAO,CAAC"}
package/package.json CHANGED
@@ -1,4 +1,61 @@
1
1
  {
2
2
  "name": "@osohq/langchain",
3
- "version": "0.0.0"
3
+ "version": "0.1.0",
4
+ "description": "Oso observability integration for LangChain agents",
5
+ "engines": {
6
+ "node": ">=16.0.0"
7
+ },
8
+ "keywords": [
9
+ "langchain",
10
+ "observability",
11
+ "oso",
12
+ "monitoring",
13
+ "authorization"
14
+ ],
15
+ "license": "Apache-2.0",
16
+ "main": "dist/index.js",
17
+ "types": "dist/index.d.ts",
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "author": "Oso Security",
22
+ "homepage": "https://www.osohq.com",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/osohq/langchain-oso-ts"
26
+ },
27
+ "scripts": {
28
+ "clean": "rimraf dist",
29
+ "lint": "eslint",
30
+ "test": "jest -i",
31
+ "ts:check": "tsc --noEmit",
32
+ "prettier:check": "prettier --check \"**/*.{js,ts,tsx,json}\"",
33
+ "prettier": "prettier --write \"**/*.{js,ts,tsx,json}\"",
34
+ "prebuild": "yarn clean",
35
+ "preversion": "yarn build",
36
+ "build": "tsc -p tsconfig.build.json",
37
+ "prepublish": "yarn build"
38
+ },
39
+ "dependencies": {
40
+ "@langchain/core": ">=0.1.0",
41
+ "cross-fetch": "^4.1.0"
42
+ },
43
+ "devDependencies": {
44
+ "@types/jest": "^29.5.12",
45
+ "@types/node": "^20.0.0",
46
+ "eslint": "^8.0.1",
47
+ "eslint-config-standard": "^17.0.0",
48
+ "eslint-plugin-import": "^2.25.2",
49
+ "eslint-plugin-jest": "^26.2.2",
50
+ "eslint-plugin-n": "^15.0.0",
51
+ "eslint-plugin-promise": "^6.0.0",
52
+ "jest": "^29.7",
53
+ "prettier": "^3.2.5",
54
+ "rimraf": "^3.0.2",
55
+ "ts-jest": "^29.1.4",
56
+ "typescript": "^5.4.5"
57
+ },
58
+ "peerDependencies": {
59
+ "@langchain/core": ">=0.1.0"
60
+ }
4
61
  }