@reminix/langchain 0.0.7 → 0.0.8
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/README.md +9 -23
- package/dist/agent-adapter.d.ts +12 -27
- package/dist/agent-adapter.d.ts.map +1 -1
- package/dist/agent-adapter.js +22 -79
- package/dist/agent-adapter.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -35,8 +35,7 @@ serve({ agents: [agent], port: 8080 });
|
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
Your agent is now available at:
|
|
38
|
-
- `POST /agents/my-chatbot/
|
|
39
|
-
- `POST /agents/my-chatbot/chat` - Conversational chat
|
|
38
|
+
- `POST /agents/my-chatbot/execute` - Execute the agent
|
|
40
39
|
|
|
41
40
|
## API Reference
|
|
42
41
|
|
|
@@ -85,16 +84,14 @@ serve({ agents: [agent], port: 8080 });
|
|
|
85
84
|
|
|
86
85
|
## Endpoint Input/Output Formats
|
|
87
86
|
|
|
88
|
-
### POST /agents/{name}/
|
|
87
|
+
### POST /agents/{name}/execute
|
|
89
88
|
|
|
90
|
-
|
|
89
|
+
Execute the agent. Input keys are passed directly to the LangChain runnable.
|
|
91
90
|
|
|
92
91
|
**Request:**
|
|
93
92
|
```json
|
|
94
93
|
{
|
|
95
|
-
"input":
|
|
96
|
-
"input": "Hello, how are you?"
|
|
97
|
-
}
|
|
94
|
+
"input": "Hello, how are you?"
|
|
98
95
|
}
|
|
99
96
|
```
|
|
100
97
|
|
|
@@ -105,29 +102,18 @@ Stateless invocation. Input is passed directly to the LangChain runnable.
|
|
|
105
102
|
}
|
|
106
103
|
```
|
|
107
104
|
|
|
108
|
-
###
|
|
105
|
+
### Streaming
|
|
109
106
|
|
|
110
|
-
|
|
107
|
+
For streaming responses, set `stream: true` in the request:
|
|
111
108
|
|
|
112
|
-
**Request:**
|
|
113
109
|
```json
|
|
114
110
|
{
|
|
115
|
-
"
|
|
116
|
-
|
|
117
|
-
]
|
|
111
|
+
"input": "Tell me a story",
|
|
112
|
+
"stream": true
|
|
118
113
|
}
|
|
119
114
|
```
|
|
120
115
|
|
|
121
|
-
|
|
122
|
-
```json
|
|
123
|
-
{
|
|
124
|
-
"output": "The capital of France is Paris.",
|
|
125
|
-
"messages": [
|
|
126
|
-
{"role": "user", "content": "What is the capital of France?"},
|
|
127
|
-
{"role": "assistant", "content": "The capital of France is Paris."}
|
|
128
|
-
]
|
|
129
|
-
}
|
|
130
|
-
```
|
|
116
|
+
The response will be sent as Server-Sent Events (SSE).
|
|
131
117
|
|
|
132
118
|
## Runtime Documentation
|
|
133
119
|
|
package/dist/agent-adapter.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* LangChain adapter for Reminix Runtime.
|
|
3
3
|
*/
|
|
4
4
|
import type { Runnable } from '@langchain/core/runnables';
|
|
5
|
-
import { AgentAdapter, type ServeOptions, type
|
|
5
|
+
import { AgentAdapter, type ServeOptions, type ExecuteRequest, type ExecuteResponse } from '@reminix/runtime';
|
|
6
6
|
/**
|
|
7
7
|
* Adapter for LangChain agents and runnables.
|
|
8
8
|
*/
|
|
@@ -23,41 +23,26 @@ export declare class LangChainAgentAdapter extends AgentAdapter {
|
|
|
23
23
|
*/
|
|
24
24
|
private toLangChainMessage;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Build LangChain input from execute request.
|
|
27
27
|
*/
|
|
28
|
-
private
|
|
28
|
+
private buildLangChainInput;
|
|
29
29
|
/**
|
|
30
|
-
* Handle an
|
|
30
|
+
* Handle an execute request.
|
|
31
31
|
*
|
|
32
|
-
* For task-oriented operations.
|
|
32
|
+
* For both task-oriented and chat-style operations. Expects input with 'messages' key
|
|
33
|
+
* or a 'prompt' key for simple text generation.
|
|
33
34
|
*
|
|
34
|
-
* @param request - The
|
|
35
|
-
* @returns The
|
|
35
|
+
* @param request - The execute request with input data.
|
|
36
|
+
* @returns The execute response with the output.
|
|
36
37
|
*/
|
|
37
|
-
|
|
38
|
+
execute(request: ExecuteRequest): Promise<ExecuteResponse>;
|
|
38
39
|
/**
|
|
39
|
-
* Handle a
|
|
40
|
+
* Handle a streaming execute request.
|
|
40
41
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* @param request - The chat request with messages.
|
|
44
|
-
* @returns The chat response with output and messages.
|
|
45
|
-
*/
|
|
46
|
-
chat(request: ChatRequest): Promise<ChatResponse>;
|
|
47
|
-
/**
|
|
48
|
-
* Handle a streaming invoke request.
|
|
49
|
-
*
|
|
50
|
-
* @param request - The invoke request with input data.
|
|
51
|
-
* @yields JSON-encoded chunks from the stream.
|
|
52
|
-
*/
|
|
53
|
-
invokeStream(request: InvokeRequest): AsyncGenerator<string, void, unknown>;
|
|
54
|
-
/**
|
|
55
|
-
* Handle a streaming chat request.
|
|
56
|
-
*
|
|
57
|
-
* @param request - The chat request with messages.
|
|
42
|
+
* @param request - The execute request with input data.
|
|
58
43
|
* @yields JSON-encoded chunks from the stream.
|
|
59
44
|
*/
|
|
60
|
-
|
|
45
|
+
executeStream(request: ExecuteRequest): AsyncGenerator<string, void, unknown>;
|
|
61
46
|
}
|
|
62
47
|
/**
|
|
63
48
|
* Wrap a LangChain agent for use with Reminix Runtime.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-adapter.d.ts","sourceRoot":"","sources":["../src/agent-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EACL,YAAY,EAEZ,KAAK,YAAY,EACjB,KAAK,
|
|
1
|
+
{"version":3,"file":"agent-adapter.d.ts","sourceRoot":"","sources":["../src/agent-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EACL,YAAY,EAEZ,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,eAAe,EAErB,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,YAAY;IACrD,MAAM,CAAC,WAAW,SAAe;IAEjC,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,KAAK,CAAS;IAEtB;;;;;OAKG;gBACS,KAAK,EAAE,QAAQ,EAAE,IAAI,GAAE,MAA0B;IAM7D,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAqB1B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAa3B;;;;;;;;OAQG;IACG,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;IAkBhE;;;;;OAKG;IACI,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC;CAgBrF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,QAAQ,EACf,IAAI,GAAE,MAA0B,GAC/B,qBAAqB,CAEvB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,YAAY;IACvD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,GAAE,mBAAwB,GAAG,IAAI,CAInF"}
|
package/dist/agent-adapter.js
CHANGED
|
@@ -47,39 +47,33 @@ export class LangChainAgentAdapter extends AgentAdapter {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
50
|
+
* Build LangChain input from execute request.
|
|
51
51
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (
|
|
55
|
-
|
|
52
|
+
buildLangChainInput(request) {
|
|
53
|
+
const input = request.input;
|
|
54
|
+
if ('messages' in input) {
|
|
55
|
+
const messages = input.messages;
|
|
56
|
+
return messages.map((m) => this.toLangChainMessage(m));
|
|
56
57
|
}
|
|
57
|
-
else if (
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
else if (message instanceof SystemMessage) {
|
|
61
|
-
role = 'system';
|
|
62
|
-
}
|
|
63
|
-
else if (message instanceof ToolMessage) {
|
|
64
|
-
role = 'tool';
|
|
58
|
+
else if ('prompt' in input) {
|
|
59
|
+
return input.prompt;
|
|
65
60
|
}
|
|
66
61
|
else {
|
|
67
|
-
|
|
62
|
+
return input;
|
|
68
63
|
}
|
|
69
|
-
const content = typeof message.content === 'string' ? message.content : String(message.content);
|
|
70
|
-
return { role, content };
|
|
71
64
|
}
|
|
72
65
|
/**
|
|
73
|
-
* Handle an
|
|
66
|
+
* Handle an execute request.
|
|
74
67
|
*
|
|
75
|
-
* For task-oriented operations.
|
|
68
|
+
* For both task-oriented and chat-style operations. Expects input with 'messages' key
|
|
69
|
+
* or a 'prompt' key for simple text generation.
|
|
76
70
|
*
|
|
77
|
-
* @param request - The
|
|
78
|
-
* @returns The
|
|
71
|
+
* @param request - The execute request with input data.
|
|
72
|
+
* @returns The execute response with the output.
|
|
79
73
|
*/
|
|
80
|
-
async
|
|
81
|
-
|
|
82
|
-
const response = await this.agent.invoke(
|
|
74
|
+
async execute(request) {
|
|
75
|
+
const invokeInput = this.buildLangChainInput(request);
|
|
76
|
+
const response = await this.agent.invoke(invokeInput);
|
|
83
77
|
// Extract output from response
|
|
84
78
|
let output;
|
|
85
79
|
if (response && typeof response === 'object' && 'content' in response) {
|
|
@@ -94,66 +88,15 @@ export class LangChainAgentAdapter extends AgentAdapter {
|
|
|
94
88
|
return { output };
|
|
95
89
|
}
|
|
96
90
|
/**
|
|
97
|
-
* Handle a
|
|
98
|
-
*
|
|
99
|
-
* For conversational interactions. Converts messages to LangChain format.
|
|
100
|
-
*
|
|
101
|
-
* @param request - The chat request with messages.
|
|
102
|
-
* @returns The chat response with output and messages.
|
|
103
|
-
*/
|
|
104
|
-
async chat(request) {
|
|
105
|
-
// Convert messages to LangChain format
|
|
106
|
-
const lcMessages = request.messages.map((m) => this.toLangChainMessage(m));
|
|
107
|
-
// Call the runnable
|
|
108
|
-
const response = await this.agent.invoke(lcMessages);
|
|
109
|
-
// Extract content from response
|
|
110
|
-
let output;
|
|
111
|
-
let responseMessage;
|
|
112
|
-
if (response && typeof response === 'object' && 'content' in response) {
|
|
113
|
-
output = typeof response.content === 'string' ? response.content : String(response.content);
|
|
114
|
-
responseMessage = this.toReminixMessage(response);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
output = String(response);
|
|
118
|
-
responseMessage = { role: 'assistant', content: output };
|
|
119
|
-
}
|
|
120
|
-
// Build response messages (original + assistant response)
|
|
121
|
-
const responseMessages = [...request.messages, responseMessage];
|
|
122
|
-
return { output, messages: responseMessages };
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Handle a streaming invoke request.
|
|
126
|
-
*
|
|
127
|
-
* @param request - The invoke request with input data.
|
|
128
|
-
* @yields JSON-encoded chunks from the stream.
|
|
129
|
-
*/
|
|
130
|
-
async *invokeStream(request) {
|
|
131
|
-
// Stream from the runnable
|
|
132
|
-
for await (const chunk of await this.agent.stream(request.input)) {
|
|
133
|
-
let content;
|
|
134
|
-
if (chunk && typeof chunk === 'object' && 'content' in chunk) {
|
|
135
|
-
content = typeof chunk.content === 'string' ? chunk.content : String(chunk.content);
|
|
136
|
-
}
|
|
137
|
-
else if (typeof chunk === 'object') {
|
|
138
|
-
content = JSON.stringify(chunk);
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
content = String(chunk);
|
|
142
|
-
}
|
|
143
|
-
yield JSON.stringify({ chunk: content });
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Handle a streaming chat request.
|
|
91
|
+
* Handle a streaming execute request.
|
|
148
92
|
*
|
|
149
|
-
* @param request - The
|
|
93
|
+
* @param request - The execute request with input data.
|
|
150
94
|
* @yields JSON-encoded chunks from the stream.
|
|
151
95
|
*/
|
|
152
|
-
async *
|
|
153
|
-
|
|
154
|
-
const lcMessages = request.messages.map((m) => this.toLangChainMessage(m));
|
|
96
|
+
async *executeStream(request) {
|
|
97
|
+
const streamInput = this.buildLangChainInput(request);
|
|
155
98
|
// Stream from the runnable
|
|
156
|
-
for await (const chunk of await this.agent.stream(
|
|
99
|
+
for await (const chunk of await this.agent.stream(streamInput)) {
|
|
157
100
|
let content;
|
|
158
101
|
if (chunk && typeof chunk === 'object' && 'content' in chunk) {
|
|
159
102
|
content = typeof chunk.content === 'string' ? chunk.content : String(chunk.content);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-adapter.js","sourceRoot":"","sources":["../src/agent-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,YAAY,EACZ,SAAS,EACT,aAAa,EACb,WAAW,GAEZ,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,YAAY,EACZ,KAAK,
|
|
1
|
+
{"version":3,"file":"agent-adapter.js","sourceRoot":"","sources":["../src/agent-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,YAAY,EACZ,SAAS,EACT,aAAa,EACb,WAAW,GAEZ,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,YAAY,EACZ,KAAK,GAKN,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,YAAY;IACrD,MAAM,CAAC,WAAW,GAAG,WAAW,CAAC;IAEzB,KAAK,CAAW;IAChB,KAAK,CAAS;IAEtB;;;;;OAKG;IACH,YAAY,KAAe,EAAE,OAAe,iBAAiB;QAC3D,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACp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,EAAE,CAAC;gBACrC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YAClC,CAAC;iBAAM,CAAC;gBACN,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YAC1B,CAAC;YACD,MAAM,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;;AAGH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,SAAS,CACvB,KAAe,EACf,OAAe,iBAAiB;IAEhC,OAAO,IAAI,qBAAqB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AAChD,CAAC;AASD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,UAAU,CAAC,KAAe,EAAE,UAA+B,EAAE;IAC3E,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IACzC,MAAM,YAAY,GAAG,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC5C,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;AACpD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reminix/langchain",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Reminix adapter for LangChain - serve agents as REST APIs",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"LICENSE"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@reminix/runtime": "^0.0.
|
|
48
|
+
"@reminix/runtime": "^0.0.8"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@langchain/core": ">=1.1.0"
|