Skip to content

Commit a47fa95

Browse files
committed
Adjust ChatAgent
1 parent 8fbf130 commit a47fa95

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Tool/Sources/LangChain/Agents/ChatAgent.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ public class ChatAgent: Agent {
9292
let baseScratchpad = constructBaseScratchpad(intermediateSteps: intermediateSteps)
9393
if baseScratchpad.isEmpty { return .text("") }
9494
return .text("""
95+
This was your previous work (but I haven't seen any of it! I only see what you return as final answer):
9596
\(baseScratchpad)
96-
(Continue with your `Thought:`)
97+
(Please continue with `Thought:`)
9798
""")
9899
}
99100

@@ -111,7 +112,7 @@ public class ChatAgent: Agent {
111112
let output = answer.trimmingCharacters(in: .whitespacesAndNewlines)
112113
return .finish(AgentFinish(returnValue: output, log: text))
113114
} catch {
114-
Logger.langchain.error("Could not parse LLM output final answer: \(error)")
115+
Logger.langchain.info("Could not parse LLM output final answer: \(error)")
115116
return nil
116117
}
117118
}
@@ -145,7 +146,7 @@ public class ChatAgent: Agent {
145146
),
146147
])
147148
} catch {
148-
Logger.langchain.error("Could not parse LLM output next action: \(error)")
149+
Logger.langchain.info("Could not parse LLM output next action: \(error)")
149150
return nil
150151
}
151152
}
@@ -158,7 +159,12 @@ public class ChatAgent: Agent {
158159
let finalAnswer = try? forceParser.parse(&parsableContent)
159160
.trimmingCharacters(in: .whitespacesAndNewlines)
160161

161-
return .finish(AgentFinish(returnValue: String(finalAnswer ?? text), log: text))
162+
var answer = finalAnswer ?? text
163+
if answer.isEmpty {
164+
answer = "Sorry, I don't know."
165+
}
166+
167+
return .finish(AgentFinish(returnValue: String(answer), log: text))
162168
}
163169
}
164170

0 commit comments

Comments
 (0)