@mcp-abap-adt/llm-agent 1.0.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.
Files changed (211) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +515 -0
  3. package/dist/agent.d.ts +49 -0
  4. package/dist/agent.d.ts.map +1 -0
  5. package/dist/agent.js +96 -0
  6. package/dist/agent.js.map +1 -0
  7. package/dist/agents/anthropic-agent.d.ts +32 -0
  8. package/dist/agents/anthropic-agent.d.ts.map +1 -0
  9. package/dist/agents/anthropic-agent.js +80 -0
  10. package/dist/agents/anthropic-agent.js.map +1 -0
  11. package/dist/agents/base.d.ts +64 -0
  12. package/dist/agents/base.d.ts.map +1 -0
  13. package/dist/agents/base.js +93 -0
  14. package/dist/agents/base.js.map +1 -0
  15. package/dist/agents/deepseek-agent.d.ts +31 -0
  16. package/dist/agents/deepseek-agent.d.ts.map +1 -0
  17. package/dist/agents/deepseek-agent.js +76 -0
  18. package/dist/agents/deepseek-agent.js.map +1 -0
  19. package/dist/agents/index.d.ts +9 -0
  20. package/dist/agents/index.d.ts.map +1 -0
  21. package/dist/agents/index.js +9 -0
  22. package/dist/agents/index.js.map +1 -0
  23. package/dist/agents/openai-agent.d.ts +32 -0
  24. package/dist/agents/openai-agent.d.ts.map +1 -0
  25. package/dist/agents/openai-agent.js +69 -0
  26. package/dist/agents/openai-agent.js.map +1 -0
  27. package/dist/agents/prompt-based-agent.d.ts +28 -0
  28. package/dist/agents/prompt-based-agent.d.ts.map +1 -0
  29. package/dist/agents/prompt-based-agent.js +62 -0
  30. package/dist/agents/prompt-based-agent.js.map +1 -0
  31. package/dist/agents/sap-core-ai-agent.d.ts +22 -0
  32. package/dist/agents/sap-core-ai-agent.d.ts.map +1 -0
  33. package/dist/agents/sap-core-ai-agent.js +20 -0
  34. package/dist/agents/sap-core-ai-agent.js.map +1 -0
  35. package/dist/cli.d.ts +53 -0
  36. package/dist/cli.d.ts.map +1 -0
  37. package/dist/cli.js +313 -0
  38. package/dist/cli.js.map +1 -0
  39. package/dist/index.d.ts +18 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +24 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/llm-providers/anthropic.d.ts +21 -0
  44. package/dist/llm-providers/anthropic.d.ts.map +1 -0
  45. package/dist/llm-providers/anthropic.js +58 -0
  46. package/dist/llm-providers/anthropic.js.map +1 -0
  47. package/dist/llm-providers/base.d.ts +28 -0
  48. package/dist/llm-providers/base.d.ts.map +1 -0
  49. package/dist/llm-providers/base.js +18 -0
  50. package/dist/llm-providers/base.js.map +1 -0
  51. package/dist/llm-providers/deepseek.d.ts +21 -0
  52. package/dist/llm-providers/deepseek.d.ts.map +1 -0
  53. package/dist/llm-providers/deepseek.js +50 -0
  54. package/dist/llm-providers/deepseek.js.map +1 -0
  55. package/dist/llm-providers/index.d.ts +13 -0
  56. package/dist/llm-providers/index.d.ts.map +1 -0
  57. package/dist/llm-providers/index.js +15 -0
  58. package/dist/llm-providers/index.js.map +1 -0
  59. package/dist/llm-providers/openai.d.ts +23 -0
  60. package/dist/llm-providers/openai.d.ts.map +1 -0
  61. package/dist/llm-providers/openai.js +59 -0
  62. package/dist/llm-providers/openai.js.map +1 -0
  63. package/dist/llm-providers/sap-core-ai.d.ts +72 -0
  64. package/dist/llm-providers/sap-core-ai.d.ts.map +1 -0
  65. package/dist/llm-providers/sap-core-ai.js +114 -0
  66. package/dist/llm-providers/sap-core-ai.js.map +1 -0
  67. package/dist/mcp/client.d.ts +119 -0
  68. package/dist/mcp/client.d.ts.map +1 -0
  69. package/dist/mcp/client.js +271 -0
  70. package/dist/mcp/client.js.map +1 -0
  71. package/dist/smart-agent/adapters/index.d.ts +3 -0
  72. package/dist/smart-agent/adapters/index.d.ts.map +1 -0
  73. package/dist/smart-agent/adapters/index.js +3 -0
  74. package/dist/smart-agent/adapters/index.js.map +1 -0
  75. package/dist/smart-agent/adapters/llm-adapter.d.ts +18 -0
  76. package/dist/smart-agent/adapters/llm-adapter.d.ts.map +1 -0
  77. package/dist/smart-agent/adapters/llm-adapter.js +111 -0
  78. package/dist/smart-agent/adapters/llm-adapter.js.map +1 -0
  79. package/dist/smart-agent/adapters/mcp-client-adapter.d.ts +13 -0
  80. package/dist/smart-agent/adapters/mcp-client-adapter.d.ts.map +1 -0
  81. package/dist/smart-agent/adapters/mcp-client-adapter.js +68 -0
  82. package/dist/smart-agent/adapters/mcp-client-adapter.js.map +1 -0
  83. package/dist/smart-agent/agent.d.ts +71 -0
  84. package/dist/smart-agent/agent.d.ts.map +1 -0
  85. package/dist/smart-agent/agent.js +462 -0
  86. package/dist/smart-agent/agent.js.map +1 -0
  87. package/dist/smart-agent/builder.d.ts +129 -0
  88. package/dist/smart-agent/builder.d.ts.map +1 -0
  89. package/dist/smart-agent/builder.js +230 -0
  90. package/dist/smart-agent/builder.js.map +1 -0
  91. package/dist/smart-agent/classifier/index.d.ts +3 -0
  92. package/dist/smart-agent/classifier/index.d.ts.map +1 -0
  93. package/dist/smart-agent/classifier/index.js +2 -0
  94. package/dist/smart-agent/classifier/index.js.map +1 -0
  95. package/dist/smart-agent/classifier/llm-classifier.d.ts +20 -0
  96. package/dist/smart-agent/classifier/llm-classifier.d.ts.map +1 -0
  97. package/dist/smart-agent/classifier/llm-classifier.js +121 -0
  98. package/dist/smart-agent/classifier/llm-classifier.js.map +1 -0
  99. package/dist/smart-agent/cli.d.ts +61 -0
  100. package/dist/smart-agent/cli.d.ts.map +1 -0
  101. package/dist/smart-agent/cli.js +181 -0
  102. package/dist/smart-agent/cli.js.map +1 -0
  103. package/dist/smart-agent/config.d.ts +41 -0
  104. package/dist/smart-agent/config.d.ts.map +1 -0
  105. package/dist/smart-agent/config.js +199 -0
  106. package/dist/smart-agent/config.js.map +1 -0
  107. package/dist/smart-agent/context/context-assembler.d.ts +24 -0
  108. package/dist/smart-agent/context/context-assembler.d.ts.map +1 -0
  109. package/dist/smart-agent/context/context-assembler.js +165 -0
  110. package/dist/smart-agent/context/context-assembler.js.map +1 -0
  111. package/dist/smart-agent/context/index.d.ts +3 -0
  112. package/dist/smart-agent/context/index.d.ts.map +1 -0
  113. package/dist/smart-agent/context/index.js +2 -0
  114. package/dist/smart-agent/context/index.js.map +1 -0
  115. package/dist/smart-agent/interfaces/assembler.d.ts +11 -0
  116. package/dist/smart-agent/interfaces/assembler.d.ts.map +1 -0
  117. package/dist/smart-agent/interfaces/assembler.js +2 -0
  118. package/dist/smart-agent/interfaces/assembler.js.map +1 -0
  119. package/dist/smart-agent/interfaces/classifier.d.ts +5 -0
  120. package/dist/smart-agent/interfaces/classifier.d.ts.map +1 -0
  121. package/dist/smart-agent/interfaces/classifier.js +2 -0
  122. package/dist/smart-agent/interfaces/classifier.js.map +1 -0
  123. package/dist/smart-agent/interfaces/index.d.ts +8 -0
  124. package/dist/smart-agent/interfaces/index.d.ts.map +1 -0
  125. package/dist/smart-agent/interfaces/index.js +2 -0
  126. package/dist/smart-agent/interfaces/index.js.map +1 -0
  127. package/dist/smart-agent/interfaces/llm.d.ts +6 -0
  128. package/dist/smart-agent/interfaces/llm.d.ts.map +1 -0
  129. package/dist/smart-agent/interfaces/llm.js +2 -0
  130. package/dist/smart-agent/interfaces/llm.js.map +1 -0
  131. package/dist/smart-agent/interfaces/mcp-client.d.ts +6 -0
  132. package/dist/smart-agent/interfaces/mcp-client.d.ts.map +1 -0
  133. package/dist/smart-agent/interfaces/mcp-client.js +2 -0
  134. package/dist/smart-agent/interfaces/mcp-client.js.map +1 -0
  135. package/dist/smart-agent/interfaces/rag.d.ts +6 -0
  136. package/dist/smart-agent/interfaces/rag.d.ts.map +1 -0
  137. package/dist/smart-agent/interfaces/rag.js +2 -0
  138. package/dist/smart-agent/interfaces/rag.js.map +1 -0
  139. package/dist/smart-agent/interfaces/types.d.ts +109 -0
  140. package/dist/smart-agent/interfaces/types.d.ts.map +1 -0
  141. package/dist/smart-agent/interfaces/types.js +45 -0
  142. package/dist/smart-agent/interfaces/types.js.map +1 -0
  143. package/dist/smart-agent/llm/token-counting-llm.d.ts +25 -0
  144. package/dist/smart-agent/llm/token-counting-llm.d.ts.map +1 -0
  145. package/dist/smart-agent/llm/token-counting-llm.js +56 -0
  146. package/dist/smart-agent/llm/token-counting-llm.js.map +1 -0
  147. package/dist/smart-agent/logger/console-logger.d.ts +7 -0
  148. package/dist/smart-agent/logger/console-logger.d.ts.map +1 -0
  149. package/dist/smart-agent/logger/console-logger.js +12 -0
  150. package/dist/smart-agent/logger/console-logger.js.map +1 -0
  151. package/dist/smart-agent/logger/index.d.ts +3 -0
  152. package/dist/smart-agent/logger/index.d.ts.map +1 -0
  153. package/dist/smart-agent/logger/index.js +2 -0
  154. package/dist/smart-agent/logger/index.js.map +1 -0
  155. package/dist/smart-agent/logger/types.d.ts +59 -0
  156. package/dist/smart-agent/logger/types.d.ts.map +1 -0
  157. package/dist/smart-agent/logger/types.js +2 -0
  158. package/dist/smart-agent/logger/types.js.map +1 -0
  159. package/dist/smart-agent/pipeline.d.ts +62 -0
  160. package/dist/smart-agent/pipeline.d.ts.map +1 -0
  161. package/dist/smart-agent/pipeline.js +70 -0
  162. package/dist/smart-agent/pipeline.js.map +1 -0
  163. package/dist/smart-agent/policy/heuristic-injection-detector.d.ts +5 -0
  164. package/dist/smart-agent/policy/heuristic-injection-detector.d.ts.map +1 -0
  165. package/dist/smart-agent/policy/heuristic-injection-detector.js +36 -0
  166. package/dist/smart-agent/policy/heuristic-injection-detector.js.map +1 -0
  167. package/dist/smart-agent/policy/index.d.ts +5 -0
  168. package/dist/smart-agent/policy/index.d.ts.map +1 -0
  169. package/dist/smart-agent/policy/index.js +4 -0
  170. package/dist/smart-agent/policy/index.js.map +1 -0
  171. package/dist/smart-agent/policy/tool-policy-guard.d.ts +8 -0
  172. package/dist/smart-agent/policy/tool-policy-guard.d.ts.map +1 -0
  173. package/dist/smart-agent/policy/tool-policy-guard.js +40 -0
  174. package/dist/smart-agent/policy/tool-policy-guard.js.map +1 -0
  175. package/dist/smart-agent/policy/types.d.ts +51 -0
  176. package/dist/smart-agent/policy/types.d.ts.map +1 -0
  177. package/dist/smart-agent/policy/types.js +17 -0
  178. package/dist/smart-agent/policy/types.js.map +1 -0
  179. package/dist/smart-agent/rag/in-memory-rag.d.ts +18 -0
  180. package/dist/smart-agent/rag/in-memory-rag.d.ts.map +1 -0
  181. package/dist/smart-agent/rag/in-memory-rag.js +111 -0
  182. package/dist/smart-agent/rag/in-memory-rag.js.map +1 -0
  183. package/dist/smart-agent/rag/index.d.ts +5 -0
  184. package/dist/smart-agent/rag/index.d.ts.map +1 -0
  185. package/dist/smart-agent/rag/index.js +3 -0
  186. package/dist/smart-agent/rag/index.js.map +1 -0
  187. package/dist/smart-agent/rag/ollama-rag.d.ts +25 -0
  188. package/dist/smart-agent/rag/ollama-rag.d.ts.map +1 -0
  189. package/dist/smart-agent/rag/ollama-rag.js +111 -0
  190. package/dist/smart-agent/rag/ollama-rag.js.map +1 -0
  191. package/dist/smart-agent/server.d.ts +19 -0
  192. package/dist/smart-agent/server.d.ts.map +1 -0
  193. package/dist/smart-agent/server.js +156 -0
  194. package/dist/smart-agent/server.js.map +1 -0
  195. package/dist/smart-agent/smart-server.d.ts +116 -0
  196. package/dist/smart-agent/smart-server.d.ts.map +1 -0
  197. package/dist/smart-agent/smart-server.js +230 -0
  198. package/dist/smart-agent/smart-server.js.map +1 -0
  199. package/dist/smart-agent/testing/index.d.ts +76 -0
  200. package/dist/smart-agent/testing/index.d.ts.map +1 -0
  201. package/dist/smart-agent/testing/index.js +188 -0
  202. package/dist/smart-agent/testing/index.js.map +1 -0
  203. package/dist/smoke-adapters.d.ts +17 -0
  204. package/dist/smoke-adapters.d.ts.map +1 -0
  205. package/dist/smoke-adapters.js +178 -0
  206. package/dist/smoke-adapters.js.map +1 -0
  207. package/dist/types.d.ts +54 -0
  208. package/dist/types.d.ts.map +1 -0
  209. package/dist/types.js +5 -0
  210. package/dist/types.js.map +1 -0
  211. package/package.json +89 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Cloud LLM Hub
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,515 @@
1
+ # LLM Proxy
2
+
3
+ Minimal LLM agent that normalizes provider access and surfaces MCP tools without executing them.
4
+
5
+ ## Overview
6
+
7
+ This agent acts as a thin orchestration layer between LLM providers and MCP (Model Context Protocol) servers. It provides tool catalogs to the LLM and returns the raw LLM response to the consumer.
8
+
9
+ **Provider Paths:**
10
+ - Direct providers are supported: `OpenAIProvider`, `AnthropicProvider`, `DeepSeekProvider`
11
+ - SAP AI Core gateway is also supported via `SapCoreAIProvider`
12
+ - In SAP deployments, SAP AI Core is typically the recommended integration path
13
+
14
+ ## Features
15
+
16
+ - ✅ Multiple LLM provider paths (direct providers and SAP AI Core gateway)
17
+ - ✅ MCP client integration with multiple transport protocols
18
+ - ✅ Stdio transport (for local processes)
19
+ - ✅ SSE transport (Server-Sent Events)
20
+ - ✅ Streamable HTTP transport (bidirectional NDJSON)
21
+ - ✅ Auto-detection of transport from URL
22
+ - ✅ Tool catalog surfacing (no tool execution at this layer)
23
+ - ✅ Conversation history management
24
+ - ✅ Raw LLM response passthrough for consumers
25
+ - 🔄 Streaming support (planned)
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ npm install @mcp-abap-adt/llm-agent
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ The agent can be used in two ways:
36
+
37
+ 1. **Embedded in application** - Import and use directly in your CAP service or application (same process)
38
+ 2. **Standalone service** - Run as a separate service/process
39
+
40
+ Both modes connect to MCP servers via transport protocols (HTTP/SSE/stdio), not directly to MCP server instances.
41
+
42
+ ### Embedded Usage (Same Process)
43
+
44
+ When using the agent embedded in your application (e.g., in `cloud-llm-hub` CAP service), you import it as a module:
45
+
46
+ ```typescript
47
+ // srv/agent-service.ts
48
+ import { SapCoreAIAgent, SapCoreAIProvider, MCPClientWrapper } from '@mcp-abap-adt/llm-agent';
49
+ import { executeHttpRequest } from '@sap-cloud-sdk/http-client';
50
+
51
+ export default class AgentService extends cds.Service {
52
+ private agent: SapCoreAIAgent;
53
+
54
+ async init() {
55
+ // Create SAP AI Core provider (all LLM providers through SAP AI Core)
56
+ const llmProvider = new SapCoreAIProvider({
57
+ destinationName: 'SAP_AI_CORE_DEST', // SAP destination for AI Core
58
+ model: 'gpt-4o-mini', // Model name determines which provider SAP AI Core uses
59
+ httpClient: async (config) => {
60
+ return await executeHttpRequest(
61
+ { destinationName: config.destinationName },
62
+ {
63
+ method: config.method as any,
64
+ url: config.url,
65
+ headers: config.headers,
66
+ data: config.data,
67
+ }
68
+ );
69
+ },
70
+ });
71
+
72
+ // Create MCP client
73
+ const mcpClient = new MCPClientWrapper({
74
+ url: 'http://localhost:4004/mcp/stream/http', // MCP proxy endpoint
75
+ headers: {
76
+ 'Authorization': 'Basic YWxpY2U6',
77
+ 'X-SAP-Destination': 'SAP_DEV_DEST',
78
+ },
79
+ });
80
+
81
+ // Create agent
82
+ this.agent = new SapCoreAIAgent({
83
+ llmProvider,
84
+ mcpClient,
85
+ });
86
+
87
+ await this.agent.connect();
88
+ }
89
+
90
+ async chat(message: string) {
91
+ return await this.agent.process(message);
92
+ }
93
+ }
94
+ ```
95
+
96
+ **Architecture Note:**
97
+ - The agent is imported as a module (like `@fr0ster/mcp-abap-adt`)
98
+ - Even when embedded in the same process, the agent connects to the MCP proxy via HTTP transport
99
+ - The MCP proxy embeds the `mcp-abap-adt` server instance
100
+ - This keeps the architecture clean: agent → MCP proxy (via HTTP) → embedded MCP server
101
+
102
+ See [Embedded Usage Guide](../../docs/LLM_AGENT_EMBEDDED_USAGE.md) for complete examples including per-request agent instances and caching strategies.
103
+
104
+ ### Standalone Usage (Separate Process)
105
+
106
+ ### Basic Example (Stdio Transport)
107
+
108
+ ```typescript
109
+ import { SapCoreAIAgent, SapCoreAIProvider, MCPClientWrapper } from '@mcp-abap-adt/llm-agent';
110
+ import { executeHttpRequest } from '@sap-cloud-sdk/http-client';
111
+
112
+ // Create SAP AI Core provider
113
+ const llmProvider = new SapCoreAIProvider({
114
+ destinationName: 'SAP_AI_CORE_DEST',
115
+ model: 'gpt-4o-mini', // Routes to OpenAI through SAP AI Core
116
+ httpClient: async (config) => {
117
+ return await executeHttpRequest(
118
+ { destinationName: config.destinationName },
119
+ {
120
+ method: config.method as any,
121
+ url: config.url,
122
+ headers: config.headers,
123
+ data: config.data,
124
+ }
125
+ );
126
+ },
127
+ });
128
+
129
+ const mcpClient = new MCPClientWrapper({
130
+ transport: 'stdio',
131
+ command: 'node',
132
+ args: ['path/to/mcp-server.js'],
133
+ });
134
+
135
+ const agent = new SapCoreAIAgent({
136
+ llmProvider,
137
+ mcpClient,
138
+ });
139
+
140
+ await agent.connect();
141
+ const response = await agent.process('What tools are available?');
142
+ console.log(response.message);
143
+ ```
144
+
145
+ ### HTTP Transport (Auto-Detection)
146
+
147
+ ```typescript
148
+ import { Agent, OpenAIProvider, MCPClientWrapper } from '@mcp-abap-adt/llm-agent';
149
+
150
+ const llmProvider = new OpenAIProvider({
151
+ apiKey: process.env.OPENAI_API_KEY!,
152
+ model: 'gpt-4o-mini',
153
+ });
154
+
155
+ // Auto-detects 'stream-http' from URL
156
+ const mcpClient = new MCPClientWrapper({
157
+ url: 'http://localhost:4004/mcp/stream/http',
158
+ headers: {
159
+ 'Authorization': 'Basic YWxpY2U6',
160
+ 'Content-Type': 'application/x-ndjson',
161
+ },
162
+ });
163
+
164
+ const agent = new Agent({
165
+ llmProvider,
166
+ mcpClient,
167
+ });
168
+
169
+ await mcpClient.connect();
170
+ const sessionId = mcpClient.getSessionId(); // Get session ID for subsequent requests
171
+
172
+ const response = await agent.process('What tools are available?');
173
+ // The response is returned as-is; tool execution is handled by the consumer.
174
+ console.log(response.message);
175
+ ```
176
+
177
+ ### Explicit Transport Selection
178
+
179
+ ```typescript
180
+ // SSE transport
181
+ const sseClient = new MCPClientWrapper({
182
+ transport: 'sse',
183
+ url: 'http://localhost:4004/mcp/stream/sse',
184
+ headers: {
185
+ 'Authorization': 'Basic YWxpY2U6',
186
+ },
187
+ });
188
+
189
+ // Streamable HTTP transport
190
+ const httpClient = new MCPClientWrapper({
191
+ transport: 'stream-http',
192
+ url: 'http://localhost:4004/mcp/stream/http',
193
+ headers: {
194
+ 'Authorization': 'Basic YWxpY2U6',
195
+ },
196
+ });
197
+ ```
198
+
199
+ See [src/mcp/README.md](src/mcp/README.md) for detailed transport configuration options.
200
+
201
+ ### Embedded Usage in CAP Service
202
+
203
+ The agent can be imported and used directly in CAP services, similar to how `mcp-abap-adt` is used:
204
+
205
+ ```typescript
206
+ // srv/agent-service.ts
207
+ import { Agent, OpenAIProvider } from '@mcp-abap-adt/llm-agent';
208
+
209
+ export default class AgentService extends cds.Service {
210
+ private agent: Agent;
211
+
212
+ async init() {
213
+ this.agent = new Agent({
214
+ llmProvider: new OpenAIProvider({
215
+ apiKey: process.env.OPENAI_API_KEY!,
216
+ }),
217
+ mcpConfig: {
218
+ url: 'http://localhost:4004/mcp/stream/http',
219
+ headers: {
220
+ 'Authorization': 'Basic YWxpY2U6',
221
+ 'X-SAP-Destination': 'SAP_DEV_DEST',
222
+ },
223
+ },
224
+ });
225
+
226
+ await this.agent.connect();
227
+ }
228
+
229
+ async chat(message: string) {
230
+ return await this.agent.process(message);
231
+ }
232
+ }
233
+ ```
234
+
235
+ See [docs/LLM_AGENT_EMBEDDED_USAGE.md](../../docs/LLM_AGENT_EMBEDDED_USAGE.md) for complete embedded usage guide.
236
+
237
+ ## Development
238
+
239
+ **Cross-Platform Development:** This project is configured for consistent behavior across Windows, Linux, and macOS. See the parent project's [Cross-Platform Development Guide](../../docs/CROSS_PLATFORM_GUIDE.md) for setup instructions and troubleshooting.
240
+
241
+ **Verify your setup:** Run `npm run verify:setup` from the root project to check cross-platform configuration.
242
+
243
+ ```bash
244
+ # Install dependencies
245
+ npm install
246
+
247
+ # Setup environment (copy template and fill in your values)
248
+ cp .env.template .env
249
+ # Edit .env with your API keys and settings
250
+
251
+ # Build
252
+ npm run build
253
+
254
+ # Development mode (with tsx for hot reload)
255
+ # Will automatically load .env file if it exists
256
+ npm run dev
257
+
258
+ # Run test launcher (after build)
259
+ npm start
260
+
261
+ # Or with custom message
262
+ npm start "List all available ABAP programs"
263
+ ```
264
+
265
+ ### Environment Configuration
266
+
267
+ The agent supports configuration via `.env` file for easier setup:
268
+
269
+ 1. Copy the template:
270
+ ```bash
271
+ cp .env.template .env
272
+ ```
273
+
274
+ 2. Edit `.env` with your settings:
275
+ ```bash
276
+ # Direct provider configuration (used by current CLI launcher)
277
+ LLM_PROVIDER=openai # openai | anthropic | deepseek
278
+ OPENAI_API_KEY=sk-proj-your-key
279
+ OPENAI_MODEL=gpt-4o-mini
280
+
281
+ # MCP Configuration (optional, for MCP integration)
282
+ MCP_ENDPOINT=http://localhost:4004/mcp/stream/http
283
+ MCP_DISABLED=false
284
+ ```
285
+
286
+ **Optional (library-level SAP AI Core provider):**
287
+ SAP_CORE_AI_URL=https://api.ai.core.sap
288
+ SAP_CORE_AI_DESTINATION=SAP_AI_CORE_DEST
289
+
290
+ 3. Run the agent - it will automatically load `.env`:
291
+ ```bash
292
+ npm run dev:llm
293
+ ```
294
+
295
+ Environment variables from `.env` can be overridden by actual environment variables.
296
+
297
+ ### Test Launcher
298
+
299
+ The agent includes a simple CLI test launcher for quick testing.
300
+
301
+ **Note:** The current CLI launcher uses direct providers (`openai`, `anthropic`, `deepseek`). `ollama` is listed in comments but not implemented.
302
+
303
+ #### Test LLM Only (Without MCP)
304
+
305
+ Test just the LLM provider without MCP integration:
306
+
307
+ **OpenAI:**
308
+ ```bash
309
+ # Basic usage - set API key and run
310
+ export OPENAI_API_KEY="sk-proj-your-actual-key-here"
311
+ npm run dev:llm
312
+
313
+ # Or inline
314
+ OPENAI_API_KEY="sk-proj-your-key" npm run dev:llm
315
+
316
+ # With custom message
317
+ export OPENAI_API_KEY="sk-proj-your-key"
318
+ npm run dev:llm "Hello! Can you introduce yourself?"
319
+
320
+ # With specific model
321
+ export OPENAI_API_KEY="sk-proj-your-key"
322
+ export OPENAI_MODEL="gpt-4o" # or gpt-4-turbo, gpt-4o-mini, etc.
323
+ npm run dev:llm
324
+
325
+ # With organization ID (for team accounts)
326
+ export OPENAI_API_KEY="sk-proj-your-key"
327
+ export OPENAI_ORG="org-your-org-id"
328
+ npm run dev:llm
329
+
330
+ # With project ID (for project-specific billing)
331
+ export OPENAI_API_KEY="sk-proj-your-key"
332
+ export OPENAI_PROJECT="proj-your-project-id" # or OPENAI_PRJ
333
+ npm run dev:llm
334
+
335
+ # Full configuration
336
+ export OPENAI_API_KEY="sk-proj-your-key"
337
+ export OPENAI_MODEL="gpt-4o"
338
+ export OPENAI_ORG="org-your-org-id"
339
+ export OPENAI_PROJECT="proj-your-project-id"
340
+ npm run dev:llm
341
+ ```
342
+
343
+ **Anthropic (Claude):**
344
+ ```bash
345
+ # Set provider and API key
346
+ export LLM_PROVIDER=anthropic
347
+ export ANTHROPIC_API_KEY="sk-ant-your-actual-key-here"
348
+ npm run dev:llm
349
+
350
+ # With custom message
351
+ export LLM_PROVIDER=anthropic
352
+ export ANTHROPIC_API_KEY="sk-ant-your-key"
353
+ npm run dev:llm "What can you do?"
354
+
355
+ # With specific model
356
+ export LLM_PROVIDER=anthropic
357
+ export ANTHROPIC_API_KEY="sk-ant-your-key"
358
+ export ANTHROPIC_MODEL="claude-3-5-sonnet-20241022" # or claude-3-opus, etc.
359
+ npm run dev:llm
360
+ ```
361
+
362
+ **DeepSeek:**
363
+ ```bash
364
+ # Set provider and API key
365
+ export LLM_PROVIDER=deepseek
366
+ export DEEPSEEK_API_KEY="sk-your-actual-key-here"
367
+ npm run dev:llm
368
+
369
+ # With custom message
370
+ export LLM_PROVIDER=deepseek
371
+ export DEEPSEEK_API_KEY="sk-your-key"
372
+ npm run dev:llm "Explain what you can do"
373
+ ```
374
+
375
+ **Alternative methods:**
376
+ ```bash
377
+ # Method 1: Using dedicated script (recommended)
378
+ export OPENAI_API_KEY="sk-proj-..."
379
+ npm run dev:llm
380
+
381
+ # Method 2: Using flag
382
+ export OPENAI_API_KEY="sk-proj-..."
383
+ npm run dev -- --llm-only
384
+
385
+ # Method 3: Using environment variable
386
+ export OPENAI_API_KEY="sk-proj-..."
387
+ export MCP_DISABLED=true
388
+ npm run dev
389
+ ```
390
+
391
+ #### Basic Usage with OpenAI (With MCP)
392
+
393
+ ```bash
394
+ # Method 1: Export environment variable
395
+ export OPENAI_API_KEY="sk-proj-..."
396
+ export MCP_ENDPOINT="http://localhost:4004/mcp/stream/http"
397
+ npm run dev
398
+
399
+ # Method 2: Inline (one-time use)
400
+ OPENAI_API_KEY="sk-proj-..." npm run dev
401
+
402
+ # Method 3: With custom message
403
+ export OPENAI_API_KEY="sk-proj-..."
404
+ npm run dev "What ABAP programs are available?"
405
+
406
+ # Method 4: Using .env file (if you have dotenv setup)
407
+ # Create .env file:
408
+ # OPENAI_API_KEY=sk-proj-...
409
+ # MCP_ENDPOINT=http://localhost:4004/mcp/stream/http
410
+ npm run dev
411
+ ```
412
+
413
+ #### Complete Example
414
+
415
+ ```bash
416
+ # From project root
417
+ cd submodules/llm-agent
418
+
419
+ # Set required environment variables
420
+ export OPENAI_API_KEY="sk-proj-your-actual-key-here"
421
+ export MCP_ENDPOINT="http://localhost:4004/mcp/stream/http"
422
+ export SAP_DESTINATION="SAP_DEV_DEST" # Optional, for SAP integration
423
+
424
+ # Optional: Set model
425
+ export OPENAI_MODEL="gpt-4o-mini" # or gpt-4o, gpt-4-turbo, etc.
426
+
427
+ # Run test launcher
428
+ npm run dev
429
+
430
+ # Or with custom message
431
+ npm run dev "List all available tools and describe what they do"
432
+ ```
433
+
434
+ #### Testing with Different LLM Providers
435
+
436
+ **Anthropic (Claude):**
437
+ ```bash
438
+ export LLM_PROVIDER=anthropic
439
+ export ANTHROPIC_API_KEY="sk-ant-your-key-here"
440
+ export ANTHROPIC_MODEL="claude-3-5-sonnet-20241022" # Optional
441
+ npm run dev
442
+ ```
443
+
444
+ **DeepSeek:**
445
+ ```bash
446
+ export LLM_PROVIDER=deepseek
447
+ export DEEPSEEK_API_KEY="sk-your-key-here"
448
+ export DEEPSEEK_MODEL="deepseek-chat" # Optional
449
+ npm run dev
450
+ ```
451
+
452
+ #### Example Output
453
+
454
+ ```
455
+ 🤖 LLM Proxy Test Launcher v0.0.1
456
+
457
+ 📋 Configuration:
458
+ LLM Provider: openai
459
+ MCP Endpoint: http://localhost:4004/mcp/stream/http
460
+ Test Message: What tools are available?
461
+
462
+ ✅ Created OpenAI provider
463
+ ✅ Created MCP client
464
+
465
+ ✅ Created agent instance
466
+ Agent type: OpenAIAgent
467
+
468
+ 🔌 Connecting to MCP server...
469
+ ✅ Connected to MCP server
470
+
471
+ 📦 Available tools: 31
472
+ - GetProgram: Retrieve ABAP program source code...
473
+ - GetClass: Retrieve ABAP class source code...
474
+ - GetFunction: Retrieve ABAP function module...
475
+ ... and 28 more
476
+
477
+ 💬 Processing message: "What tools are available?"
478
+
479
+ 📤 Response:
480
+ ────────────────────────────────────────────────────────────
481
+ I can see you have 31 tools available for working with ABAP systems...
482
+
483
+ ⏱️ Duration: 2341ms
484
+
485
+ 📜 Conversation history: 4 messages
486
+
487
+ ✅ Test completed successfully!
488
+ ```
489
+
490
+ The test launcher will:
491
+ - Connect to MCP server
492
+ - List available tools
493
+ - Process a test message
494
+ - Show response
495
+ - Display conversation history
496
+
497
+ ## Tool Execution Responsibility
498
+
499
+ The agent does not execute tools. It only:
500
+ - Fetches MCP tool catalogs
501
+ - Passes tool definitions to the LLM
502
+ - Returns the raw LLM response to the consumer
503
+
504
+ If your application needs tool execution, parse the model output in the consumer layer and call MCP tools there.
505
+
506
+ ## Architecture
507
+
508
+ - `src/agents/` - Agent implementations (BaseAgent, SapCoreAIAgent, etc.)
509
+ - `src/llm-providers/` - LLM provider implementations (OpenAI, Anthropic, DeepSeek, SapCoreAI)
510
+ - `src/mcp/` - MCP client wrapper
511
+ - `src/types.ts` - TypeScript type definitions
512
+
513
+ ## License
514
+
515
+ MIT
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Core Agent Orchestrator
3
+ *
4
+ * Coordinates between LLM provider and MCP tools
5
+ */
6
+ import type { LLMProvider } from './llm-providers/base.js';
7
+ import { type MCPClientConfig, MCPClientWrapper } from './mcp/client.js';
8
+ import type { AgentResponse, Message } from './types.js';
9
+ export interface AgentConfig {
10
+ llmProvider: LLMProvider;
11
+ /**
12
+ * MCP client instance (if provided, will be used directly)
13
+ * If not provided, will be created from mcpConfig
14
+ */
15
+ mcpClient?: MCPClientWrapper;
16
+ /**
17
+ * Direct MCP configuration (used if mcpClient is not provided)
18
+ * If both mcpClient and mcpConfig are provided, mcpClient takes precedence
19
+ */
20
+ mcpConfig?: MCPClientConfig;
21
+ maxIterations?: number;
22
+ }
23
+ export declare class Agent {
24
+ private llmProvider;
25
+ private mcpClient;
26
+ private conversationHistory;
27
+ constructor(config: AgentConfig);
28
+ /**
29
+ * Initialize MCP client connection (call this before using the agent)
30
+ */
31
+ connect(): Promise<void>;
32
+ /**
33
+ * Process a user message and return agent response
34
+ */
35
+ process(userMessage: string): Promise<AgentResponse>;
36
+ /**
37
+ * Build system message with tool definitions
38
+ */
39
+ private buildSystemMessage;
40
+ /**
41
+ * Clear conversation history
42
+ */
43
+ clearHistory(): void;
44
+ /**
45
+ * Get conversation history
46
+ */
47
+ getHistory(): Message[];
48
+ }
49
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,KAAK,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEzD,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,WAAW,CAAC;IACzB;;;OAGG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B;;;OAGG;IACH,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,qBAAa,KAAK;IAChB,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,SAAS,CAAmB;IACpC,OAAO,CAAC,mBAAmB,CAAiB;gBAEhC,MAAM,EAAE,WAAW;IAe/B;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B;;OAEG;IACG,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAyC1D;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAc1B;;OAEG;IACH,YAAY,IAAI,IAAI;IAIpB;;OAEG;IACH,UAAU,IAAI,OAAO,EAAE;CAGxB"}
package/dist/agent.js ADDED
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Core Agent Orchestrator
3
+ *
4
+ * Coordinates between LLM provider and MCP tools
5
+ */
6
+ import { MCPClientWrapper } from './mcp/client.js';
7
+ export class Agent {
8
+ llmProvider;
9
+ mcpClient;
10
+ conversationHistory = [];
11
+ constructor(config) {
12
+ this.llmProvider = config.llmProvider;
13
+ // Initialize MCP client
14
+ if (config.mcpClient) {
15
+ this.mcpClient = config.mcpClient;
16
+ }
17
+ else if (config.mcpConfig) {
18
+ this.mcpClient = new MCPClientWrapper(config.mcpConfig);
19
+ }
20
+ else {
21
+ throw new Error('MCP client configuration required. Provide either mcpClient or mcpConfig.');
22
+ }
23
+ }
24
+ /**
25
+ * Initialize MCP client connection (call this before using the agent)
26
+ */
27
+ async connect() {
28
+ await this.mcpClient.connect();
29
+ }
30
+ /**
31
+ * Process a user message and return agent response
32
+ */
33
+ async process(userMessage) {
34
+ try {
35
+ // Add user message to history
36
+ this.conversationHistory.push({
37
+ role: 'user',
38
+ content: userMessage,
39
+ });
40
+ // Get available tools from MCP
41
+ const tools = await this.mcpClient.listTools();
42
+ // Build system message with tool definitions
43
+ const systemMessage = this.buildSystemMessage(tools);
44
+ // Prepare messages for LLM
45
+ const messages = [
46
+ { role: 'system', content: systemMessage },
47
+ ...this.conversationHistory,
48
+ ];
49
+ // Get LLM response
50
+ const llmResponse = await this.llmProvider.chat(messages);
51
+ // Add assistant response to history
52
+ this.conversationHistory.push({
53
+ role: 'assistant',
54
+ content: llmResponse.content,
55
+ });
56
+ return {
57
+ message: llmResponse.content,
58
+ raw: llmResponse.raw,
59
+ };
60
+ }
61
+ catch (error) {
62
+ return {
63
+ message: '',
64
+ error: error.message || 'Agent processing failed',
65
+ };
66
+ }
67
+ }
68
+ /**
69
+ * Build system message with tool definitions
70
+ */
71
+ buildSystemMessage(tools) {
72
+ const toolDescriptions = tools
73
+ .map((tool) => {
74
+ return `- ${tool.name}: ${tool.description || 'No description'}`;
75
+ })
76
+ .join('\n');
77
+ return `You are a helpful assistant with access to the following tools:
78
+
79
+ ${toolDescriptions}
80
+
81
+ If using a tool is required, describe the tool call and its parameters in your response.`;
82
+ }
83
+ /**
84
+ * Clear conversation history
85
+ */
86
+ clearHistory() {
87
+ this.conversationHistory = [];
88
+ }
89
+ /**
90
+ * Get conversation history
91
+ */
92
+ getHistory() {
93
+ return [...this.conversationHistory];
94
+ }
95
+ }
96
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAwB,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAkBzE,MAAM,OAAO,KAAK;IACR,WAAW,CAAc;IACzB,SAAS,CAAmB;IAC5B,mBAAmB,GAAc,EAAE,CAAC;IAE5C,YAAY,MAAmB;QAC7B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QAEtC,wBAAwB;QACxB,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;YACrB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QACpC,CAAC;aAAM,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;YAC5B,IAAI,CAAC,SAAS,GAAG,IAAI,gBAAgB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC1D,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,WAAmB;QAC/B,IAAI,CAAC;YACH,8BAA8B;YAC9B,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC;gBAC5B,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,WAAW;aACrB,CAAC,CAAC;YAEH,+BAA+B;YAC/B,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC;YAE/C,6CAA6C;YAC7C,MAAM,aAAa,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;YAErD,2BAA2B;YAC3B,MAAM,QAAQ,GAAc;gBAC1B,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE;gBAC1C,GAAG,IAAI,CAAC,mBAAmB;aAC5B,CAAC;YAEF,mBAAmB;YACnB,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAE1D,oCAAoC;YACpC,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC;gBAC5B,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE,WAAW,CAAC,OAAO;aAC7B,CAAC,CAAC;YAEH,OAAO;gBACL,OAAO,EAAE,WAAW,CAAC,OAAO;gBAC5B,GAAG,EAAE,WAAW,CAAC,GAAG;aACrB,CAAC;QACJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO;gBACL,OAAO,EAAE,EAAE;gBACX,KAAK,EAAE,KAAK,CAAC,OAAO,IAAI,yBAAyB;aAClD,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;OAEG;IACK,kBAAkB,CAAC,KAAY;QACrC,MAAM,gBAAgB,GAAG,KAAK;aAC3B,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;YACZ,OAAO,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,WAAW,IAAI,gBAAgB,EAAE,CAAC;QACnE,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QAEd,OAAO;;EAET,gBAAgB;;yFAEuE,CAAC;IACxF,CAAC;IAED;;OAEG;IACH,YAAY;QACV,IAAI,CAAC,mBAAmB,GAAG,EAAE,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,CAAC,GAAG,IAAI,CAAC,mBAAmB,CAAC,CAAC;IACvC,CAAC;CACF"}