From 49a8a0a246ae707f3539974791cadcc2209e3cc9 Mon Sep 17 00:00:00 2001 From: bsorrentino Date: Mon, 5 Aug 2024 09:19:49 +0200 Subject: [PATCH 1/3] refactor: rename param name 'schema' to 'channels' langgraph.js compliance --- Sources/LangGraph/LangGraph.swift | 8 ++++---- Tests/LangGraphTests/LangGraphTests.swift | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/LangGraph/LangGraph.swift b/Sources/LangGraph/LangGraph.swift index 8063a60..4c7d913 100644 --- a/Sources/LangGraph/LangGraph.swift +++ b/Sources/LangGraph/LangGraph.swift @@ -212,7 +212,7 @@ public class StateGraph { let schema: Channels init( owner: StateGraph ) { - self.schema = owner.schema + self.schema = owner.channels self.stateFactory = owner.stateFactory self.nodes = Dictionary() self.edges = Dictionary() @@ -411,10 +411,10 @@ public class StateGraph { private var finishPoint: String? private var stateFactory: StateFactory - private var schema: Channels + private var channels: Channels - public init( schema: Channels = [:], stateFactory: @escaping StateFactory ) { - self.schema = schema + public init( channels: Channels = [:], stateFactory: @escaping StateFactory ) { + self.channels = channels self.stateFactory = stateFactory } diff --git a/Tests/LangGraphTests/LangGraphTests.swift b/Tests/LangGraphTests/LangGraphTests.swift index da1d705..821f7dc 100644 --- a/Tests/LangGraphTests/LangGraphTests.swift +++ b/Tests/LangGraphTests/LangGraphTests.swift @@ -286,7 +286,7 @@ final class LangGraphTests: XCTestCase { func testAppender() async throws { - let workflow = StateGraph( schema: AgentStateWithAppender.schema ) { AgentStateWithAppender($0) } + let workflow = StateGraph( channels: AgentStateWithAppender.schema ) { AgentStateWithAppender($0) } try workflow.addNode("agent_1") { state in @@ -320,7 +320,7 @@ final class LangGraphTests: XCTestCase { func testWithStream() async throws { - let workflow = StateGraph( schema: AgentStateWithAppender.schema ) { AgentStateWithAppender( $0 ) } + let workflow = StateGraph( channels: AgentStateWithAppender.schema ) { AgentStateWithAppender( $0 ) } try workflow.addNode("agent_1") { state in ["messages": "message1"] @@ -356,7 +356,7 @@ final class LangGraphTests: XCTestCase { func testWithStreamAnCancellation() async throws { - let workflow = StateGraph( schema: AgentStateWithAppender.schema ) { AgentStateWithAppender($0) } + let workflow = StateGraph( channels: AgentStateWithAppender.schema ) { AgentStateWithAppender($0) } try workflow.addNode("agent_1") { state in try await Task.sleep(nanoseconds: 500_000_000) From 1f449590227b3e8595a196510b98dc5e6fdf34df Mon Sep 17 00:00:00 2001 From: bsorrentino Date: Mon, 5 Aug 2024 09:26:13 +0200 Subject: [PATCH 2/3] refactor: rename param name 'schema' to 'channels' langgraph.js compliance --- LangChainDemo/LangChainDemo/AgentExecutor.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LangChainDemo/LangChainDemo/AgentExecutor.swift b/LangChainDemo/LangChainDemo/AgentExecutor.swift index 82367b6..9cef0e3 100644 --- a/LangChainDemo/LangChainDemo/AgentExecutor.swift +++ b/LangChainDemo/LangChainDemo/AgentExecutor.swift @@ -152,7 +152,7 @@ public func runAgent( input: String, llm: LLM, tools: [BaseTool], callbacks: [Ba } - let workflow = StateGraph( schema: AgentExecutorState.schema ) { + let workflow = StateGraph( channels: AgentExecutorState.schema ) { AgentExecutorState( $0 ) } From 92354f0ea426863e310a0241c356cef79006cd99 Mon Sep 17 00:00:00 2001 From: bsorrentino Date: Mon, 5 Aug 2024 09:26:23 +0200 Subject: [PATCH 3/3] docs: update readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d930730..99cc894 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ To use the LangGraph for Swift library in a [SwiftPM] project, add the following line to the dependencies in your `Package.swift` file: ```Swift -.package(url: "https://github.com/bsorrentino/LangGraph-Swift.git", from: "1.0.0"), +.package(url: "https://github.com/bsorrentino/LangGraph-Swift.git", from: "3.0.1"), ``` Include `LangGraph` as a dependency for your executable target: @@ -94,10 +94,10 @@ In the [LangChainDemo](LangChainDemo) project, you can find the porting of [Agen } - let workflow = StateGraph { - AgentExecutorState($0) // $0 is the initial state provided by the graph + let workflow = StateGraph( channels: AgentExecutorState.schema ) { + AgentExecutorState( $0 ) } - + try workflow.addNode("call_agent" ) { state in guard let input = state.input else {