Skip to content

Commit

Permalink
refactor(AgentExecutor): apply new names
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Jul 1, 2024
1 parent 2414f64 commit 2a1e495
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions LangChainDemo/LangChainDemo/AgentExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct AgentExecutorState : AgentState {

init() {
self.init([
"intermediate_steps": AppendableValue(),
"intermediate_steps": AppendableValue<(AgentAction, String)>(),
"chat_history": AppendableValue()
])
}
Expand Down Expand Up @@ -99,7 +99,7 @@ public func runAgent( input: String, llm: LLM, tools: [BaseTool], callbacks: [Ba

let toolExecutor = { (action: AgentAction) in
guard let tool = tools.filter({$0.name() == action.action}).first else {
throw GraphRunnerError.executionError("tool \(action.action) not found!")
throw CompiledGraphError.executionError("tool \(action.action) not found!")
}

do {
Expand Down Expand Up @@ -151,7 +151,7 @@ public func runAgent( input: String, llm: LLM, tools: [BaseTool], callbacks: [Ba
}


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

Expand All @@ -175,10 +175,10 @@ public func runAgent( input: String, llm: LLM, tools: [BaseTool], callbacks: [Ba
try workflow.addNode("call_agent" ) { state in

guard let input = state.input else {
throw GraphRunnerError.executionError("'input' argument not found in state!")
throw CompiledGraphError.executionError("'input' argument not found in state!")
}
guard let intermediate_steps = state.intermediate_steps else {
throw GraphRunnerError.executionError("'intermediate_steps' property not found in state!")
throw CompiledGraphError.executionError("'intermediate_steps' property not found in state!")
}

onAgentStart( input )
Expand All @@ -191,18 +191,18 @@ public func runAgent( input: String, llm: LLM, tools: [BaseTool], callbacks: [Ba
onAgentAction( action )
return [ "agent_outcome": AgentOutcome.action(action) ]
default:
throw GraphRunnerError.executionError( "Parsed.error" )
throw CompiledGraphError.executionError( "Parsed.error" )
}
}

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

guard let agentOutcome = state.agentOutcome else {
throw GraphRunnerError.executionError("'agent_outcome' property not found in state!")
throw CompiledGraphError.executionError("'agent_outcome' property not found in state!")
}

guard case .action(let action) = agentOutcome else {
throw GraphRunnerError.executionError("'agent_outcome' is not an action!")
throw CompiledGraphError.executionError("'agent_outcome' is not an action!")
}

let result = try await toolExecutor( action )
Expand All @@ -218,7 +218,7 @@ public func runAgent( input: String, llm: LLM, tools: [BaseTool], callbacks: [Ba
try workflow.addConditionalEdge( sourceId: "call_agent", condition: { state in

guard let agentOutcome = state.agentOutcome else {
throw GraphRunnerError.executionError("'agent_outcome' property not found in state!")
throw CompiledGraphError.executionError("'agent_outcome' property not found in state!")
}

return switch agentOutcome {
Expand Down

0 comments on commit 2a1e495

Please sign in to comment.