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

fix: xml component working properly #3822

Merged
merged 6 commits into from
Sep 18, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions src/backend/base/langflow/components/agents/XMLAgent.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import List, Optional
from langchain.agents import create_xml_agent
from langchain_core.prompts import ChatPromptTemplate, PromptTemplate, HumanMessagePromptTemplate

from langflow.base.agents.agent import LCToolsAgentComponent
from langflow.inputs import MultilineInput
from langflow.inputs.inputs import HandleInput
from langflow.inputs.inputs import DataInput, HandleInput
from langflow.schema import Data


class XMLAgentComponent(LCToolsAgentComponent):
Expand All @@ -12,43 +13,38 @@ class XMLAgentComponent(LCToolsAgentComponent):
icon = "LangChain"
beta = True
name = "XMLAgent"

inputs = LCToolsAgentComponent._base_inputs + [
HandleInput(name="llm", display_name="Language Model", input_types=["LanguageModel"], required=True),
DataInput(name="chat_history", display_name="Chat History", is_list=True, advanced=True),
MultilineInput(
name="user_prompt",
display_name="Prompt",
value="""
You are a helpful assistant. Help the user answer any questions.

value="""You are a helpful assistant. Help the user answer any questions.
You have access to the following tools:

{tools}

In order to use a tool, you can use <tool></tool> and <tool_input></tool_input> tags. You will then get back a response in the form <observation></observation>

For example, if you have a tool called 'search' that could run a google search, in order to search for the weather in SF you would respond:

<tool>search</tool><tool_input>weather in SF</tool_input>

<observation>64 degrees</observation>

When you are done, respond with a final answer between <final_answer></final_answer>. For example:

<final_answer>The weather in SF is 64 degrees</final_answer>

Begin!

Question: {input}

{agent_scratchpad}
Copy link
Contributor

Choose a reason for hiding this comment

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

Changing the prompt shouldn't be necessary and is probably not a good idea.

Copy link
Collaborator Author

@Cristhianzl Cristhianzl Sep 16, 2024

Choose a reason for hiding this comment

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

@ogabrielluiz Actually, I will just remove the first "enter" space to improve the UX.

image

""",
),
]

def get_chat_history_data(self) -> Optional[List[Data]]:
return self.chat_history

def create_agent_runnable(self):
messages = [
HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=["input"], template=self.user_prompt))
HumanMessagePromptTemplate(
prompt=PromptTemplate(
input_variables=["input", "chat_history", "agent_scratchpad", "tools"], template=self.user_prompt
)
)
]
prompt = ChatPromptTemplate.from_messages(messages)
return create_xml_agent(self.llm, self.tools, prompt)
ogabrielluiz marked this conversation as resolved.
Show resolved Hide resolved
Loading