@@ -20,7 +20,7 @@ struct AgentExecutorState : AgentState {
20
20
21
21
init ( ) {
22
22
self . init ( [
23
- " intermediate_steps " : AppendableValue ( ) ,
23
+ " intermediate_steps " : AppendableValue < ( AgentAction , String ) > ( ) ,
24
24
" chat_history " : AppendableValue ( )
25
25
] )
26
26
}
@@ -58,7 +58,7 @@ struct AgentExecutorState : AgentState {
58
58
struct ToolOutputParser : BaseOutputParser {
59
59
public init ( ) { }
60
60
public func parse( text: String ) -> Parsed {
61
- print ( text. uppercased ( ) )
61
+ print ( " \n ------- \n \( text. uppercased ( ) ) \n ------- \n " )
62
62
let pattern = " Action \\ s*:[ \\ s]*(.*)[ \\ s]*Action \\ s*Input \\ s*:[ \\ s]*(.*) "
63
63
let regex = try ! NSRegularExpression ( pattern: pattern)
64
64
@@ -99,7 +99,7 @@ public func runAgent( input: String, llm: LLM, tools: [BaseTool], callbacks: [Ba
99
99
100
100
let toolExecutor = { ( action: AgentAction ) in
101
101
guard let tool = tools. filter ( { $0. name ( ) == action. action} ) . first else {
102
- throw GraphRunnerError . executionError ( " tool \( action. action) not found! " )
102
+ throw CompiledGraphError . executionError ( " tool \( action. action) not found! " )
103
103
}
104
104
105
105
do {
@@ -151,7 +151,7 @@ public func runAgent( input: String, llm: LLM, tools: [BaseTool], callbacks: [Ba
151
151
}
152
152
153
153
154
- let workflow = GraphState {
154
+ let workflow = StateGraph {
155
155
AgentExecutorState ( )
156
156
}
157
157
@@ -175,10 +175,10 @@ public func runAgent( input: String, llm: LLM, tools: [BaseTool], callbacks: [Ba
175
175
try workflow. addNode ( " call_agent " ) { state in
176
176
177
177
guard let input = state. input else {
178
- throw GraphRunnerError . executionError ( " 'input' argument not found in state! " )
178
+ throw CompiledGraphError . executionError ( " 'input' argument not found in state! " )
179
179
}
180
180
guard let intermediate_steps = state. intermediate_steps else {
181
- throw GraphRunnerError . executionError ( " 'intermediate_steps' property not found in state! " )
181
+ throw CompiledGraphError . executionError ( " 'intermediate_steps' property not found in state! " )
182
182
}
183
183
184
184
onAgentStart ( input )
@@ -191,18 +191,18 @@ public func runAgent( input: String, llm: LLM, tools: [BaseTool], callbacks: [Ba
191
191
onAgentAction ( action )
192
192
return [ " agent_outcome " : AgentOutcome . action ( action) ]
193
193
default :
194
- throw GraphRunnerError . executionError ( " Parsed.error " )
194
+ throw CompiledGraphError . executionError ( " Parsed.error " )
195
195
}
196
196
}
197
197
198
198
try workflow. addNode ( " call_action " ) { state in
199
199
200
200
guard let agentOutcome = state. agentOutcome else {
201
- throw GraphRunnerError . executionError ( " 'agent_outcome' property not found in state! " )
201
+ throw CompiledGraphError . executionError ( " 'agent_outcome' property not found in state! " )
202
202
}
203
203
204
204
guard case . action( let action) = agentOutcome else {
205
- throw GraphRunnerError . executionError ( " 'agent_outcome' is not an action! " )
205
+ throw CompiledGraphError . executionError ( " 'agent_outcome' is not an action! " )
206
206
}
207
207
208
208
let result = try await toolExecutor ( action )
@@ -218,7 +218,7 @@ public func runAgent( input: String, llm: LLM, tools: [BaseTool], callbacks: [Ba
218
218
try workflow. addConditionalEdge ( sourceId: " call_agent " , condition: { state in
219
219
220
220
guard let agentOutcome = state. agentOutcome else {
221
- throw GraphRunnerError . executionError ( " 'agent_outcome' property not found in state! " )
221
+ throw CompiledGraphError . executionError ( " 'agent_outcome' property not found in state! " )
222
222
}
223
223
224
224
return switch agentOutcome {
0 commit comments