跳到主要内容
本指南快速介绍了如何在 langchain_taiga 中开始使用 Taiga 工具。有关每个工具和配置的更多详细信息,请参阅您的仓库或相关文档页面中的文档字符串。

概览

集成详情

类别可序列化JS 支持版本
create_entity_tool, search_entities_tool, get_entity_by_ref_tool, update_entity_by_ref_tool , add_comment_by_ref_tool, add_attachment_by_ref_toollangchain-taiga不适用待定PyPI - Version

工具特性

  • create_entity_tool:在 Taiga 中创建用户故事、任务和问题。
  • search_entities_tool:在 Taiga 中搜索用户故事、任务和问题。
  • get_entity_by_ref_tool:根据引用获取用户故事、任务或问题。
  • update_entity_by_ref_tool:根据引用更新用户故事、任务或问题。
  • add_comment_by_ref_tool:向用户故事、任务或问题添加评论。
  • add_attachment_by_ref_tool:向用户故事、任务或问题添加附件。

设置

此集成位于 langchain-taiga 包中。
pip install --quiet -U langchain-taiga
/home/henlein/Workspace/PyCharm/langchain/.venv/bin/python: No module named pip
Note: you may need to restart the kernel to use updated packages.

凭据

此集成要求您将 TAIGA_URLTAIGA_API_URLTAIGA_USERNAMETAIGA_PASSWORDOPENAI_API_KEY 设置为环境变量,以便通过 Taiga 进行身份验证。
export TAIGA_URL="https://taiga.xyz.org/"
export TAIGA_API_URL="https://taiga.xyz.org/"
export TAIGA_USERNAME="username"
export TAIGA_PASSWORD="pw"
export OPENAI_API_KEY="OPENAI_API_KEY"
设置 LangSmith 以获得一流的可观察性也很有帮助(但不是必需的)
os.environ["LANGSMITH_TRACING"] = "true"
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass()

实例化

以下是展示如何在 langchain_taiga 中实例化 Taiga 工具的示例。请根据您的具体用法进行调整。
from langchain_taiga.tools.discord_read_messages import create_entity_tool
from langchain_taiga.tools.discord_send_messages import search_entities_tool

create_tool = create_entity_tool
search_tool = search_entities_tool

调用

直接使用参数调用

下面是一个简单的示例,展示如何使用字典中的关键字参数调用工具。
from langchain_taiga.tools.taiga_tools import (
    add_attachment_by_ref_tool,
    add_comment_by_ref_tool,
    create_entity_tool,
    get_entity_by_ref_tool,
    search_entities_tool,
    update_entity_by_ref_tool,
)

response = create_entity_tool.invoke(
    {
        "project_slug": "slug",
        "entity_type": "us",
        "subject": "subject",
        "status": "new",
        "description": "desc",
        "parent_ref": 5,
        "assign_to": "user",
        "due_date": "2022-01-01",
        "tags": ["tag1", "tag2"],
    }
)

response = search_entities_tool.invoke(
    {"project_slug": "slug", "query": "query", "entity_type": "task"}
)

response = get_entity_by_ref_tool.invoke(
    {"entity_type": "user_story", "project_id": 1, "ref": "1"}
)

response = update_entity_by_ref_tool.invoke(
    {"project_slug": "slug", "entity_ref": 555, "entity_type": "us"}
)


response = add_comment_by_ref_tool.invoke(
    {"project_slug": "slug", "entity_ref": 3, "entity_type": "us", "comment": "new"}
)

response = add_attachment_by_ref_tool.invoke(
    {
        "project_slug": "slug",
        "entity_ref": 3,
        "entity_type": "us",
        "attachment_url": "url",
        "content_type": "png",
        "description": "desc",
    }
)

使用 ToolCall 调用

如果您有一个模型生成的 ToolCall,请按以下所示格式将其传递给 tool.invoke()
# This is usually generated by a model, but we'll create a tool call directly for demo purposes.
model_generated_tool_call = {
    "args": {"project_slug": "slug", "query": "query", "entity_type": "task"},
    "id": "1",
    "name": search_entities_tool.name,
    "type": "tool_call",
}
tool.invoke(model_generated_tool_call)

链接

下面是一个更完整的示例,展示了如何将 create_entity_toolsearch_entities_tool 工具与 LLM 集成到链或代理中。此示例假定您有一个函数(如 create_agent),该函数可以设置一个 LangChain 风格的代理,使其能够在适当的时候调用工具。
# Example: Using Taiga Tools in an Agent

from langchain.agents import create_agent
from langchain_taiga.tools.taiga_tools import create_entity_tool, search_entities_tool


# 1. Instantiate or configure your language model
# (Replace with your actual LLM, e.g., ChatOpenAI(temperature=0))
model = ...

# 2. Build an agent that has access to these tools
agent_executor = create_agent(model, [create_entity_tool, search_entities_tool])

# 4. Formulate a user query that may invoke one or both tools
example_query = "Please create a new user story with the subject 'subject' in slug project: 'slug'"

# 5. Execute the agent in streaming mode (or however your code is structured)
events = agent_executor.stream(
    {"messages": [("user", example_query)]},
    stream_mode="values",
)

# 6. Print out the model's responses (and any tool outputs) as they arrive
for event in events:
    event["messages"][-1].pretty_print()

API 参考

请参阅以下文件中的文档字符串 以了解用法详情、参数和高级配置。
以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.