Skip to content

Commit

Permalink
refactor: rename classes
Browse files Browse the repository at this point in the history
GraphState -> StateGraph
Runner -> CompiledGraph
  • Loading branch information
bsorrentino committed Jul 1, 2024
1 parent cffde11 commit 0800db8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions Sources/LangGraph/LangGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,22 @@ public let END = "__END__" // id of the edge ending workflow

let log = Logger( subsystem: Bundle.module.bundleIdentifier ?? "langgraph", category: "main")

public class GraphState<State: AgentState> {
public class StateGraph<State: AgentState> {

enum EdgeValue /* Union */ {
case id(String)
case condition( ( EdgeCondition<State>, [String:String] ) )
}

public class Runner {
public class CompiledGraph {

var stateFactory: () -> State
var nodes:Dictionary<String, NodeAction<State>>
var edges:Dictionary<String, EdgeValue>
var entryPoint:String
var finishPoint:String?

init( owner: GraphState ) {
init( owner: StateGraph ) {

self.stateFactory = owner.stateFactory
self.nodes = Dictionary()
Expand Down Expand Up @@ -315,7 +315,7 @@ public class GraphState<State: AgentState> {
var id: String {
sourceId
}
static func == (lhs: GraphState.Edge, rhs: GraphState.Edge) -> Bool {
static func == (lhs: StateGraph.Edge, rhs: StateGraph.Edge) -> Bool {
lhs.id == rhs.id
}

Expand All @@ -331,7 +331,7 @@ public class GraphState<State: AgentState> {
private var edges: Set<Edge> = []

struct Node : Hashable, Identifiable {
static func == (lhs: GraphState.Node, rhs: GraphState.Node) -> Bool {
static func == (lhs: StateGraph.Node, rhs: StateGraph.Node) -> Bool {
lhs.id == rhs.id
}

Expand Down Expand Up @@ -407,7 +407,7 @@ public class GraphState<State: AgentState> {
Node(id: id, action: fakeAction)
}

public func compile() throws -> Runner {
public func compile() throws -> CompiledGraph {
guard let entryPoint else {
throw GraphStateError.missingEntryPoint
}
Expand Down Expand Up @@ -443,6 +443,6 @@ public class GraphState<State: AgentState> {
}
}

return Runner( owner: self )
return CompiledGraph( owner: self )
}
}
14 changes: 7 additions & 7 deletions Tests/LangGraphTests/LangGraphTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final class LangGraphTests: XCTestCase {
}
func testValidation() async throws {

let workflow = GraphState { BaseAgentState() }
let workflow = StateGraph { BaseAgentState() }

XCTAssertThrowsError( try workflow.compile() ) {error in
print( error )
Expand Down Expand Up @@ -128,7 +128,7 @@ final class LangGraphTests: XCTestCase {

func testRunningOneNode() async throws {

let workflow = GraphState { BaseAgentState() }
let workflow = StateGraph { BaseAgentState() }
try workflow.setEntryPoint("agent_1")
try workflow.addNode("agent_1") { state in

Expand Down Expand Up @@ -171,7 +171,7 @@ final class LangGraphTests: XCTestCase {

func testRunningTreeNodes() async throws {

let workflow = GraphState { BinaryOpState() }
let workflow = StateGraph { BinaryOpState() }

try workflow.addNode("agent_1") { state in

Expand Down Expand Up @@ -209,7 +209,7 @@ final class LangGraphTests: XCTestCase {

func testRunningFourNodesWithCondition() async throws {

let workflow = GraphState { BinaryOpState() }
let workflow = StateGraph { BinaryOpState() }

try workflow.addNode("agent_1") { state in

Expand Down Expand Up @@ -293,7 +293,7 @@ final class LangGraphTests: XCTestCase {

func testAppender() async throws {

let workflow = GraphState { AgentStateWithAppender() }
let workflow = StateGraph { AgentStateWithAppender() }

try workflow.addNode("agent_1") { state in

Expand Down Expand Up @@ -327,7 +327,7 @@ final class LangGraphTests: XCTestCase {

func testWithStream() async throws {

let workflow = GraphState { AgentStateWithAppender() }
let workflow = StateGraph { AgentStateWithAppender() }

try workflow.addNode("agent_1") { state in
["messages": "message1"]
Expand Down Expand Up @@ -363,7 +363,7 @@ final class LangGraphTests: XCTestCase {

func testWithStreamAnCancellation() async throws {

let workflow = GraphState { AgentStateWithAppender() }
let workflow = StateGraph { AgentStateWithAppender() }

try workflow.addNode("agent_1") { state in
try await Task.sleep(nanoseconds: 500_000_000)
Expand Down

0 comments on commit 0800db8

Please sign in to comment.