Skip to content

Commit

Permalink
Fix breaking tags (#6765)
Browse files Browse the repository at this point in the history
Fix tags change that broke old way of initializing agent

Closes #6756
  • Loading branch information
vowelparrot committed Jun 26, 2023
1 parent ba62276 commit 6d30acf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion langchain/agents/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def initialize_agent(
f"Got unknown agent type: {agent}. "
f"Valid types are: {AGENT_TO_CLASS.keys()}."
)
tags_.append(agent.value)
tags_.append(agent.value if isinstance(agent, AgentType) else agent)
agent_cls = AGENT_TO_CLASS[agent]
agent_kwargs = agent_kwargs or {}
agent_obj = agent_cls.from_llm_and_tools(
Expand Down
23 changes: 23 additions & 0 deletions tests/unit_tests/agents/test_initialize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Test the initialize module."""

from langchain.agents.agent_types import AgentType
from langchain.agents.initialize import initialize_agent
from langchain.tools.base import tool
from tests.unit_tests.llms.fake_llm import FakeLLM


@tool
def my_tool(query: str) -> str:
"""A fake tool."""
return "fake tool"


def test_initialize_agent_with_str_agent_type() -> None:
"""Test initialize_agent with a string."""
fake_llm = FakeLLM()
agent_executor = initialize_agent(
[my_tool], fake_llm, "zero-shot-react-description" # type: ignore
)
assert agent_executor.agent._agent_type == AgentType.ZERO_SHOT_REACT_DESCRIPTION
assert isinstance(agent_executor.tags, list)
assert "zero-shot-react-description" in agent_executor.tags

0 comments on commit 6d30acf

Please sign in to comment.