-
Notifications
You must be signed in to change notification settings - Fork 15.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to custom prompt in agent type CHAT_CONVERSATIONAL_REACT_DESCRIPTION #10721
Comments
🤖 Hello, To overwrite the Here is an example of how you can do this: from libs.langchain.langchain.agents.conversational_chat.base import ConversationalChatAgent
from libs.langchain.langchain.agents.utils import validate_tools_single_input
from langchain.tools.base import BaseTool
# Define your tools
tools = [BaseTool(name="tool1", description="description1"), BaseTool(name="tool2", description="description2")]
# Define your language model
llm = ...
# Overwrite PREFIX, SUFFIX, and FORMAT_INSTRUCTIONS
new_prefix = "Your new prefix text here."
new_suffix = "Your new suffix text here."
new_format_instructions = "Your new format instructions here."
# Now, you can call the from_llm_and_tools method
agent = ConversationalChatAgent.from_llm_and_tools(
llm=llm,
tools=tools,
system_message=new_prefix,
human_message=new_suffix,
output_parser=new_format_instructions
) Please replace This will overwrite the default In the LangChain framework, the
I hope this helps! Let me know if you have any other questions. Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
We've created a subclass of the ConvoOutputParser and that way it is possible to edit the get_format_instructions() method to load your custom format instructions. |
same question, it looks like you have to define custom agent, wondering if there is a way to define it similar to AgentType.CHAT_CONVERSATIONAL_REACT_DESCRIPTION |
@spartan-minhbui format_instructions not working the agent not take consideration this property |
Yes, but you cannot set your own format instructions without defining a new class, because you are importing a variable and passing it to a function as it is done here:
There is a way to pass this parameter in the init as you do in agents and other functions:
And another way to do it directly in the agent, in the
Particullarly the second option will allow you to define the
Maybe a combination of both solutions would be great. I'll try a PR, any thought about this @guidorietbroek ? |
This doesn't work, if you pass the
|
…able (#16945) **Description:** With this modification, users can customize the `FORMAT_INSTRUCTIONS` template, allowing them to create their own prompts As it is happening in [this](#10721) issue, the `FORMAT_INSTRUCTIONS` is not customizable for the output parser, unless you create your own class `ConvoOutputParser`. To avoid this, a modification was done, creating a `format_instruction` variable that users can customize with ease after initialize the agent. For example: ``` agent = initialize_agent( agent = AgentType.CHAT_CONVERSATIONAL_REACT_DESCRIPTION, tools = tools, llm = llm_agent, verbose = True, max_iterations = 3, early_stopping_method = 'generate', memory = b_w_memory, handle_parsing_errors = True, agent_kwargs={ 'system_message':PREFIX, 'human_message':SUFFIX, 'template_tool_response':TEMPLATE_TOOL_RESPONSE, } ) agent.agent.output_parser.format_instructions = "MY CUSTOM FORMAT INSTRUCTIONS" print(agent.agent.output_parser.get_format_instructions()) MY CUSTOM FORMAT INSTRUCTIONS ``` Other parameters like `system_message`, `human_message`, or `template_tool_response` are already customizable and with this PR, the last parameter `FORMAT_INSTRUCTIONS` in `langchain.agents.conversational_chat.prompt` can be modified. **Issue:** #10721 **Dependencies:** No new dependencies required for this change **Twitter handle:** With my github user is enough. Thanks I hope you accept my PR. --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
…custom `FORMAT_INSTRUCTIONS` (#17168) - **Description:** This PR standardizes the `output_parser.py` file across all agent types to ensure a uniform parsing mechanism is implemented. It introduces a cohesive structure and common interface for output parsing, facilitating easier modifications and extensions by users. The standardized approach enhances maintainability and scalability of the codebase by providing a consistent pattern for output parsing, which can be easily understood and utilized across different agent types. This PR builds upon the foundation set by a previously merged PR, which focused exclusively on standardizing the `output_parser.py` for the `conversational_agent` ([PR #16945](#16945)). With this new update, I extend the standardization efforts to encompass `output_parser.py` files across all agent types. This enhancement not only unifies the parsing mechanism across the board but also introduces the flexibility for users to incorporate custom `FORMAT_INSTRUCTIONS`. - **Issue:** #10721 #4044 - **Dependencies:** No new dependencies required for this change - **Twitter handle:** With my github user is enough. Thanks I hope you accept my PR.
how to overwrite the PREFIX, SUFFIX and FORMAT_INSTRUCTIONS when I using the CHAT_CONVERSATIONAL_REACT_DESCRIPTION and creating agent by
initialize_agent
function?The text was updated successfully, but these errors were encountered: