@@ -18,19 +18,22 @@ public actor AgentExecutor<InnerAgent: Agent>: Chain
1818 var earlyStopHandleType : AgentEarlyStopHandleType
1919 var now : ( ) -> Date = { Date ( ) }
2020 var isCancelled = false
21+ var initialSteps : [ AgentAction ]
2122
2223 public init (
2324 agent: InnerAgent ,
2425 tools: [ AgentTool ] ,
2526 maxIteration: Int ? = 10 ,
2627 maxExecutionTime: Double ? = nil ,
27- earlyStopHandleType: AgentEarlyStopHandleType = . force
28+ earlyStopHandleType: AgentEarlyStopHandleType = . force,
29+ initialSteps: [ AgentAction ] = [ ]
2830 ) {
2931 self . agent = agent
3032 self . tools = tools. reduce ( into: [ : ] ) { $0 [ $1. name] = $1 }
3133 self . maxIteration = maxIteration
3234 self . maxExecutionTime = maxExecutionTime
3335 self . earlyStopHandleType = earlyStopHandleType
36+ self . initialSteps = initialSteps
3437 }
3538
3639 public func callLogic(
@@ -41,7 +44,7 @@ public actor AgentExecutor<InnerAgent: Agent>: Chain
4144
4245 let startTime = now ( ) . timeIntervalSince1970
4346 var iterations = 0
44- var intermediateSteps : [ AgentAction ] = [ ]
47+ var intermediateSteps : [ AgentAction ] = initialSteps
4548
4649 func shouldContinue( ) -> Bool {
4750 if isCancelled { return false }
@@ -84,8 +87,6 @@ public actor AgentExecutor<InnerAgent: Agent>: Chain
8487 callbackManagers: callbackManagers
8588 )
8689 }
87- case . thought:
88- break
8990 }
9091 iterations += 1
9192 }
@@ -152,6 +153,10 @@ extension AgentExecutor {
152153 for action in actions {
153154 callbackManagers
154155 . forEach { $0. send ( CallbackEvents . AgentActionDidStart ( info: action) ) }
156+ if action. observation != nil {
157+ taskGroup. addTask { action }
158+ continue
159+ }
155160 guard let tool = tools [ action. toolName] else { throw InvalidToolError ( ) }
156161 taskGroup. addTask {
157162 let observation = try await tool. run ( input: action. toolInput)
@@ -169,15 +174,6 @@ extension AgentExecutor {
169174 }
170175
171176 return . actions( completedActions)
172- case let . thought( content) :
173- return . actions( [
174- . init(
175- toolName: " Thought " ,
176- toolInput: content,
177- log: " Thought: \( content) " ,
178- observation: nil
179- ) ,
180- ] )
181177 }
182178 }
183179
0 commit comments