Find answers from the community

Updated 10 months ago

Hi, how can I set the system prompt for

Hi, how can I set the system prompt for an agent?

I tried using the example at https://docs.llamaindex.ai/en/stable/examples/agent/react_agent.html#customizing-the-prompt
Plain Text
from llama_index.core.prompts import PromptTemplate
from llama_index.core.prompts.system import SHAKESPEARE_WRITING_ASSISTANT
from llama_index.core.agent import ReActAgent

SHAKESPEARE_WRITING_ASSISTANT = PromptTemplate(SHAKESPEARE_WRITING_ASSISTANT) # just a random example

agent = ReActAgent.from_tools(
    [],
    llm=llm,
    verbose=True,
)
agent.update_prompts({"agent_worker:system_prompt": SHAKESPEARE_WRITING_ASSISTANT})

This is crashing with error
Plain Text
  File "/home/x/anaconda3/envs/foo/lib/python3.10/site-packages/llama_index/core/prompts/mixin.py", line 75, in update_prompts
    raise ValueError(f"Module {module_name} not found.")
ValueError: Module agent_worker not found.
L
1 comment
The react agent needs a little TLC in this respect

I think you need to modify the ReActChatFormatter

Plain Text
from llama_index.core.agent.react.formatter import ReActChatFormatter

formatter = ReActChatFormatter(system_header=my_header)


The default system header is quite large, I would copy and modify it as needed
https://github.com/run-llama/llama_index/blob/a607f97e2f7b9e821e03dc6e0034a128b97f76f4/llama-index-core/llama_index/core/agent/react/prompts.py#L7
Add a reply
Sign up and join the conversation on Discord