Skip to content

Commit

Permalink
agents: optimize the mrkl prompt (#976)
Browse files Browse the repository at this point in the history
optimize the mrkl prompt

Co-authored-by: chensilun <[email protected]>
  • Loading branch information
Alan796 and chensilun authored Sep 13, 2024
1 parent 5082762 commit 7c553fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion agents/mrkl.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (a *OneShotZeroAgent) Plan(
fullInputs[key] = value
}

fullInputs["agent_scratchpad"] = constructScratchPad(intermediateSteps)
fullInputs["agent_scratchpad"] = constructMrklScratchPad(intermediateSteps)
fullInputs["today"] = time.Now().Format("January 02, 2006")

var stream func(ctx context.Context, chunk []byte) error
Expand Down Expand Up @@ -119,6 +119,18 @@ func (a *OneShotZeroAgent) GetTools() []tools.Tool {
return a.Tools
}

func constructMrklScratchPad(steps []schema.AgentStep) string {
var scratchPad string
if len(steps) > 0 {
for _, step := range steps {
scratchPad += "\n" + step.Action.Log
scratchPad += "\nObservation: " + step.Observation + "\n"
}
}

return scratchPad
}

func (a *OneShotZeroAgent) parseOutput(output string) ([]schema.AgentAction, *schema.AgentFinish, error) {
if strings.Contains(output, _finalAnswerAction) {
splits := strings.Split(output, _finalAnswerAction)
Expand Down
2 changes: 1 addition & 1 deletion agents/mrkl_prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Final Answer: the final answer to the original input question`
_defaultMrklSuffix = `Begin!
Question: {{.input}}
Thought:{{.agent_scratchpad}}`
{{.agent_scratchpad}}`
)

func createMRKLPrompt(tools []tools.Tool, prefix, instructions, suffix string) prompts.PromptTemplate {
Expand Down

0 comments on commit 7c553fb

Please sign in to comment.