Skip to content
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

Adding a Character Chat Agent #4411

Conversation

treppers
Copy link

@treppers treppers commented May 9, 2023

Character Chat Agent

Fork of the conversational chat agent, but added in the concept of personality and fixed some issues I was getting with the output_parser. You can provide a {character_summary} that will give your bot that personality.

I was noticing some occasional weird responses with the conversation_chat agent so rewrote the entire prompt which seemed to have fixed some of them. Also noticed some errors with output_parser (but will submit that as a separate PR).

Changes with the prompt:

  • Moving all the TOOLS and FORMAT INSTRUCTIONS into the first System Message.
  • Keeping the actual Human Message to include the original input message.
  • Introduce a third voice called TOOL, that only speaks via the System Message
  • Created a More Instructions section instead of User Input to try to trigger the Final Answer
  • Also made sure to remove most of the you's and i's and replace it with nouns (Assistant, Human, TOOL)

Output_parser changes:

  • The agent sometimes doesn't want to respond with ````json` but instead will just say ````` which breaks the split function.
  • The agent sometimes doesn't doesn't want to follow the instructions and doesn't respond with any markdown (this is usually when the prompt contains enough information to do the completion). To fix this I put a try-except to catch the when JSON fails.
  • The agent sometimes runs out of token and doesn't close the markdown snippet. Created a case to handle this case.

Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested:

@hwchase17

--------------------
Given the entire TOOLS RESPONSE,
- If the USER'S ORIGINAL INPUT isn't answered using ONLY the information obtained by TOOL, try the same tool with a different input or another tool.
- Otherwise, how would Assistant respond using information obtained from TOOL, Assistant must NOT mention the tool or tool names - the user has no context of any TOOL RESPONSES!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is a run-on sentence; could this be re-written? Perhaps something like:

Otherwise, to respond using information obtained from TOOL, Assistant must NOT mention the tool or tool names - the user has no context of any TOOL RESPONSES!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I think I had copied and pasted some of the conversational chat prompt in and it didn't make sense move on .

@@ -0,0 +1 @@
"""An agent designed to hold a conversation with a character in addition to using tools."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be more accurate to rephrase this as "An agent designed to hold a conversation as a given character in addition to using tools."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely correct!

@@ -0,0 +1,133 @@
"""An agent designed to hold a conversation with a character in addition to using tools."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be more accurate to rephrase this as "An agent designed to hold a conversation as a given character in addition to using tools."



class CharacterChatAgent(Agent):
"""An agent designed to hold a conversation in addition to using tools."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be more accurate to rephrase this as "An agent designed to hold a conversation as a given character in addition to using tools."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above. Incorporating.


When responding to the TOOL, please output a response in one of two formats:

**Option 1:**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

**Option #1:** instead of **Option 1:**

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this into the prompt.


MORE INSTRUCTIONS
--------------------
Given the entire TOOLS RESPONSE,
Copy link
Contributor

@mbchang mbchang May 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TOOLS -> TOOL

RESPONSE FORMAT INSTRUCTIONS
----------------------------

When responding to the TOOL, please output a response in one of two formats:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When responding to the TOOL -> When responding to TOOL

@mbchang
Copy link
Contributor

mbchang commented May 9, 2023

Thanks @treppers for the PR! This kind of agent looks like it could make writing dialogue agents much more streamlined.

  • It looks like you have made a few changes to the system prompt. Would you mind sharing some concrete examples (as a jupyter notebook or code snippet) that illustrate the tangible differences between using the original prompt scheme vs your proposed prompt scheme? Such an ablation study would be helpful to know whether your proposed changes are specific to the CharacterChatAgent or whether they should be incorporated more broadly into other ConversationAgents as well. Specifically, for your following changes, do you have examples of what the response would look like with and without the change?
    • Moving all the TOOLS and FORMAT INSTRUCTIONS into the first System Message.
    • Keeping the actual Human Message to include the original input message.
    • Introduce a third voice called TOOL, that only speaks via the System Message
    • Created a More Instructions section instead of User Input to try to trigger the Final Answer
    • Also made sure to remove most of the you's and i's and replace it with nouns (Assistant, Human, TOOL)
  • The CharacterChatAgent could be generalized to talk to not just the human but other characters. Could we replace "human" and "user" with "conversation partner" in the system prompt?

@treppers
Copy link
Author

Trying to put together a notebook that will do a good compare and contrast.

That should be inbound.

I do think the Conversational Chat agent needs updating and so when I get the notebook up you can see the issues I found.

Definitely open to expanding the prompt to apply to conversation partner. Would just need to test it to make sure it doesn't think the TOOL voice is a conversation partner.

Updating this branch with a notebook to execute this agent along with the suggested tweaks. Also found a bug in the prompt that was causing the Option #1 response to include additional conversational responses in addition to the markdown.

…h Option 1 included non-markdown. added a notebook to execute this.
format_instructions = character_message.format(
format_instructions=_output_parser.get_format_instructions()
)
final_prompt = format_instructions.format(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final_prompt = format_instructions.format(
system_prompt = format_instructions.format(

how about naming it to system_prompt as it is no more final?

return thoughts

@classmethod
def from_llm_and_tools(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw this piece of code in several places, ever considered inheriting ConversationalChatAgent?

@hwchase17 hwchase17 changed the base branch from master to harrison/character-chat-agent May 15, 2023 05:11
@mbchang
Copy link
Contributor

mbchang commented May 18, 2023

Thanks for the update @treppers! Curious to see what you find in the compare-and-contrast.

@dosubot dosubot bot added Ɑ: agent Related to agents module 🤖:enhancement A large net-new component, integration, or chain. Use sparingly. The largest features labels Jul 14, 2023
@efriis
Copy link
Member

efriis commented Nov 7, 2023

Hey @mbchang ! This PR no longer lines up with the current directory structure of the library (would need to be in /libs/langchain/langchain instead of /langchain). Would you be interested in updating to the new format, or would it be better to close this and someone can work on a new PR off the current state of the library (using this as a reference implementation)?

@efriis
Copy link
Member

efriis commented Nov 7, 2023

I'll close it for now, and let me know if you'd like to reopen!

@efriis efriis closed this Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ɑ: agent Related to agents module 🤖:enhancement A large net-new component, integration, or chain. Use sparingly. The largest features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants