Skip to content

Commit 95720ad

Browse files
hwchase17samching
andauthored
Add documentation for custom prompts for Agents (#631) (#640)
- Added a comment interpreting regex for `ZeroShotAgent` - Added a note to the `Custom Agent` notebook Co-authored-by: Sam Ching <[email protected]>
1 parent 6be5f4e commit 95720ad

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

docs/modules/agents/examples/custom_agent.ipynb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,17 @@
133133
"print(prompt.template)"
134134
]
135135
},
136+
{
137+
"attachments": {},
138+
"cell_type": "markdown",
139+
"id": "5e028e6d",
140+
"metadata": {},
141+
"source": [
142+
"Note that we are able to feed agents a self-defined prompt template, i.e. not restricted to the prompt generated by the `create_prompt` function, assuming it meets the agent's requirements. \n",
143+
"\n",
144+
"For example, for `ZeroShotAgent`, we will need to ensure that it meets the following requirements. There should a string starting with \"Action:\" and a following string starting with \"Action Input:\", and both should be separated by a newline.\n"
145+
]
146+
},
136147
{
137148
"cell_type": "code",
138149
"execution_count": 16,
@@ -350,7 +361,7 @@
350361
],
351362
"metadata": {
352363
"kernelspec": {
353-
"display_name": "Python 3.9.0 64-bit ('llm-env')",
364+
"display_name": "Python 3",
354365
"language": "python",
355366
"name": "python3"
356367
},
@@ -364,11 +375,11 @@
364375
"name": "python",
365376
"nbconvert_exporter": "python",
366377
"pygments_lexer": "ipython3",
367-
"version": "3.9.0"
378+
"version": "3.8.12 (default, Feb 15 2022, 17:41:09) \n[Clang 12.0.5 (clang-1205.0.22.11)]"
368379
},
369380
"vscode": {
370381
"interpreter": {
371-
"hash": "b1677b440931f40d89ef8be7bf03acb108ce003de0ac9b18e8d43753ea2e7103"
382+
"hash": "18784188d7ecd866c0586ac068b02361a6896dc3a29b64f5cc957f09c590acef"
372383
}
373384
}
374385
},

langchain/agents/mrkl/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ class ChainConfig(NamedTuple):
2828

2929

3030
def get_action_and_input(llm_output: str) -> Tuple[str, str]:
31-
"""Parse out the action and input from the LLM output."""
31+
"""Parse out the action and input from the LLM output.
32+
33+
Note: if you're specifying a custom prompt for the ZeroShotAgent,
34+
you will need to ensure that it meets the following Regex requirements.
35+
The string starting with "Action:" and the following string starting
36+
with "Action Input:" should be separated by a newline.
37+
"""
3238
if FINAL_ANSWER_ACTION in llm_output:
3339
return "Final Answer", llm_output.split(FINAL_ANSWER_ACTION)[-1].strip()
3440
regex = r"Action: (.*?)\nAction Input: (.*)"

0 commit comments

Comments
 (0)