langchain/libs
Henry eaeb8a5f71
langchain[patch]: output_parser.py in conversation_chat is customizable (#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](https://github.com/langchain-ai/langchain/issues/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:**
https://github.com/langchain-ai/langchain/issues/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>
2024-02-06 09:41:53 -08:00
..
cli docs: partner packages (#16960) 2024-02-02 15:12:21 -08:00
community community: Added new Utility runnables for NVIDIA Riva. (#15966) 2024-02-05 19:50:50 -08:00
core core[patch]: Add astream events config test (#17055) 2024-02-05 17:24:58 -08:00
experimental experimental[patch]: fixed import in experimental (#17078) 2024-02-05 17:47:13 -08:00
langchain langchain[patch]: output_parser.py in conversation_chat is customizable (#16945) 2024-02-06 09:41:53 -08:00
partners nvidia-ai-endpoints[patch]: Support User-Agent metadata and minor fixes. (#16942) 2024-02-05 12:24:53 -08:00