Skip to content

chore: Support LangGraph #633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 24, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,43 @@ exports[`orchestration service client returns successful response when maxRetrie
"id": [
"langchain_core",
"messages",
"OrchestrationMessage",
"AIMessage",
],
"kwargs": {
"additional_kwargs": {
"finish_reason": "stop",
"function_call": undefined,
"index": 0,
"module_results": {
"llm": {
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "Hello! How can I assist you today?",
"role": "assistant",
},
},
],
"created": 172,
"id": "llm-id",
"model": "gpt-4o",
"object": "chat.completion",
"usage": {
"completion_tokens": 9,
"prompt_tokens": 9,
"total_tokens": 18,
},
},
"templating": [
{
"content": "Hello!",
"role": "user",
},
],
},
"request_id": "request-id",
"tool_calls": undefined,
},
"content": "Hello! How can I assist you today?",
Expand Down Expand Up @@ -44,13 +74,43 @@ exports[`orchestration service client returns successful response when timeout i
"id": [
"langchain_core",
"messages",
"OrchestrationMessage",
"AIMessage",
],
"kwargs": {
"additional_kwargs": {
"finish_reason": "stop",
"function_call": undefined,
"index": 0,
"module_results": {
"llm": {
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "Hello! How can I assist you today?",
"role": "assistant",
},
},
],
"created": 172,
"id": "llm-id",
"model": "gpt-4o",
"object": "chat.completion",
"usage": {
"completion_tokens": 9,
"prompt_tokens": 9,
"total_tokens": 18,
},
},
"templating": [
{
"content": "Hello!",
"role": "user",
},
],
},
"request_id": "request-id",
"tool_calls": undefined,
},
"content": "Hello! How can I assist you today?",
Expand Down
33 changes: 15 additions & 18 deletions packages/langchain/src/orchestration/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OrchestrationMessage } from './orchestration-message.js';
import { AIMessage } from '@langchain/core/messages';
import type { ChatResult } from '@langchain/core/outputs';
import type {
ChatMessage,
Expand All @@ -8,7 +8,6 @@ import type {
import type { ToolCall } from '@langchain/core/messages/tool';
import type { AzureOpenAiChatCompletionMessageToolCalls } from '@sap-ai-sdk/foundation-models';
import type {
AIMessage,
BaseMessage,
HumanMessage,
SystemMessage
Expand Down Expand Up @@ -140,22 +139,20 @@ export function mapOutputToChatResult(
return {
generations: choices.map(choice => ({
text: choice.message.content ?? '',
message: new OrchestrationMessage(
{
content: choice.message.content ?? '',
tool_calls: mapAzureOpenAiToLangchainToolCall(
choice.message.tool_calls
),
additional_kwargs: {
finish_reason: choice.finish_reason,
index: choice.index,
function_call: choice.message.function_call,
tool_calls: choice.message.tool_calls
}
},
module_results,
request_id
),
message: new AIMessage({
content: choice.message.content ?? '',
tool_calls: mapAzureOpenAiToLangchainToolCall(
choice.message.tool_calls
),
additional_kwargs: {
finish_reason: choice.finish_reason,
index: choice.index,
function_call: choice.message.function_call,
tool_calls: choice.message.tool_calls,
module_results,
request_id
}
}),
generationInfo: {
finish_reason: choice.finish_reason,
index: choice.index,
Expand Down
73 changes: 69 additions & 4 deletions pnpm-lock.yaml

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

27 changes: 14 additions & 13 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
packages:
- 'packages/ai-api'
- 'packages/core'
- 'packages/foundation-models'
- 'packages/langchain'
- 'packages/orchestration'
- 'packages/document-grounding'
- 'packages/prompt-registry'
- 'sample-cap'
- 'sample-code'
- 'tests/e2e-tests'
- 'tests/schema-tests'
- 'tests/smoke-tests'
- 'tests/type-tests'
- packages/ai-api
- packages/core
- packages/foundation-models
- packages/langchain
- packages/orchestration
- packages/document-grounding
- packages/prompt-registry
- sample-cap
- sample-code
- tests/e2e-tests
- tests/schema-tests
- tests/smoke-tests
- tests/type-tests

16 changes: 9 additions & 7 deletions sample-code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@
"lint:fix": "eslint . --fix && prettier . --config ../.prettierrc --ignore-path ../.prettierignore -w --log-level error"
},
"dependencies": {
"@langchain/langgraph": "^0.2.62",
"langchain": "0.3.21",
"@langchain/core": "0.3.45",
"@langchain/textsplitters": "0.1.0",
"@sap-ai-sdk/ai-api": "workspace:^",
"@sap-ai-sdk/document-grounding": "workspace:^",
"@sap-ai-sdk/foundation-models": "workspace:^",
"@sap-ai-sdk/orchestration": "workspace:^",
"@sap-ai-sdk/langchain": "workspace:^",
"@sap-ai-sdk/document-grounding": "workspace:^",
"@sap-ai-sdk/orchestration": "workspace:^",
"@sap-ai-sdk/prompt-registry": "workspace:^",
"langchain": "0.3.21",
"@langchain/core": "0.3.45",
"@langchain/textsplitters": "0.1.0",
"@sap-cloud-sdk/util": "^4.0.2",
"@types/express": "^5.0.1",
"express": "^5.1.0",
"zod-to-json-schema": "^3.24.5",
"zod": "^3.24.3"
"uuid": "^11.1.0",
"zod": "^3.24.2",
"zod-to-json-schema": "^3.24.5"
}
}
5 changes: 4 additions & 1 deletion sample-code/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export {
invokeChain,
invokeRagChain
} from './langchain-azure-openai.js';
export { invokeChain as orchestrationInvokeChain } from './langchain-orchestration.js';
export {
invokeChain as orchestrationInvokeChain,
invokeLangGraphChain
} from './langchain-orchestration.js';
export {
getDeployments,
getDeploymentsWithDestination,
Expand Down
Loading
Loading