이 가이드는 WRITER tools 시작하기에 대한 개요를 제공합니다. 모든 WRITER 기능 및 구성에 대한 자세한 문서는 WRITER docs를 참조하세요.

Overview

Integration details

ClassPackageLocalSerializableJS supportDownloadsVersion
GraphToollangchain-writerPyPI - DownloadsPyPI - Version
TranslationToollangchain-writerPyPI - DownloadsPyPI - Version
WebSearchToollangchain-writerPyPI - DownloadsPyPI - Version

Features

ChatWriter는 여러 tool 유형을 지원합니다: function, graph, translation, web_search.
중요한 제한사항: 한 번에 하나의 WRITER tool(translation, graph, web_search, llm, image, vision)만 사용할 수 있습니다. 여러 WRITER tool을 결합할 수는 없지만, 하나의 WRITER tool과 여러 custom function tool을 함께 사용할 수 있습니다.

Function

Function은 가장 일반적인 tool 유형으로, LLM이 외부 API를 호출하고, 데이터베이스에서 데이터를 가져오며, 일반적으로 원하는 모든 외부 작업을 수행할 수 있게 합니다. 추가 정보는 WRITER의 tool calling docs를 참조하세요.

Graph

Graph tool은 WRITER의 Knowledge Graph를 사용하며, 이는 그래프 기반 retrieval-augmented generation(RAG) 시스템입니다. 이 tool을 사용할 때 개발자는 특정 Knowledge Graph를 참조하는 graph ID를 제공합니다. 그러면 모델이 이 그래프를 사용하여 관련 정보를 찾고 프롬프트의 질문에 대한 정확한 답변을 생성합니다. 이를 통해 모델이 대화 중에 사용자 정의 지식 베이스에 액세스하고 활용할 수 있습니다. 자세한 내용은 WRITER의 Knowledge Graph API docs를 참조하세요.

Translation

translation tool을 사용하면 Palmyra 모델과의 대화 중에 텍스트를 번역할 수 있습니다. Palmyra X 모델은 번역 작업을 수행할 수 있지만, 이러한 작업에 최적화되어 있지 않으며 올바른 프롬프팅 없이는 제대로 작동하지 않을 수 있습니다. 자세한 내용은 WRITER의 translation API docs를 참조하세요. web search tool을 사용하면 Palmyra 모델과의 대화 중에 웹에서 최신 정보를 검색할 수 있습니다. Palmyra 모델은 광범위한 지식을 가지고 있지만 최신 정보나 실시간 데이터에 액세스하지 못할 수 있습니다. web search tool을 사용하면 AI 어시스턴트가 웹에서 최신 정보, 뉴스 및 사실을 찾을 수 있습니다. 자세한 내용은 WRITER의 web search API docs를 참조하세요.

Setup

WRITER AI Studio에 가입하여 API key를 생성하세요(Quickstart 참조). 그런 다음 WRITER_API_KEY 환경 변수를 설정하세요:
import getpass
import os

if not os.getenv("WRITER_API_KEY"):
    os.environ["WRITER_API_KEY"] = getpass.getpass("Enter your WRITER API key: ")

Usage

graph 또는 function tool을 ChatWriter에 바인딩할 수 있습니다.

Graph Tools

graph tool을 바인딩하려면 먼저 소스로 사용할 graph_idsGraphTool 인스턴스를 생성하고 초기화하세요:
from langchain_writer.chat_models import ChatWriter
from langchain_writer.tools import GraphTool

chat = ChatWriter()

graph_id = getpass.getpass("Enter WRITER Knowledge Graph ID: ")
graph_tool = GraphTool(graph_ids=[graph_id])

Translation Tools

translation tool을 사용하면 Palmyra 모델과의 대화 중에 텍스트를 번역할 수 있습니다. Palmyra X 모델은 번역 작업을 수행할 수 있지만, 이러한 작업에 최적화되어 있지 않으며 올바른 프롬프팅 없이는 제대로 작동하지 않을 수 있습니다. translation tool을 사용하려면 내장된 TranslationTool을 import하고 초기화하세요:
from langchain_writer.tools import TranslationTool

# Initialize the translation tool
translation_tool = TranslationTool()

Web Search Tools

web search tool을 사용하면 Palmyra 모델과의 대화 중에 웹에서 최신 정보를 검색할 수 있습니다. Palmyra 모델은 광범위한 지식을 가지고 있지만 최신 정보나 실시간 데이터에 액세스하지 못할 수 있습니다. web search tool을 사용하면 AI 어시스턴트가 웹에서 최신 정보, 뉴스 및 사실을 찾을 수 있습니다. web search tool을 사용하려면 내장된 WebSearchTool을 import하고 초기화하세요:
from langchain_writer.tools import WebSearchTool

# Initialize the web search tool with optional configuration
web_search_tool = WebSearchTool(
    include_domains=["wikipedia.org", "github.com", "techcrunch.com"],
    exclude_domains=["quora.com"]
)

Instantiation

from langchain.tools import tool
from pydantic import BaseModel, Field


@tool
def get_supercopa_trophies_count(club_name: str) -> int | None:
    """Returns information about supercopa trophies count.

    Args:
        club_name: Club you want to investigate info of supercopa trophies about

    Returns:
        Number of supercopa trophies or None if there is no info about requested club
    """

    if club_name == "Barcelona":
        return 15
    elif club_name == "Real Madrid":
        return 13
    elif club_name == "Atletico Madrid":
        return 2
    else:
        return None


class GetWeather(BaseModel):
    """Get the current weather in a given location"""

    location: str = Field(..., description="The city and state, e.g. San Francisco, CA")


get_product_info = {
    "type": "function",
    "function": {
        "name": "get_product_info",
        "description": "Get information about a product by its id",
        "parameters": {
            "type": "object",
            "properties": {
                "product_id": {
                    "type": "number",
                    "description": "The unique identifier of the product to retrieve information for",
                }
            },
            "required": ["product_id"],
        },
    },
}

Binding tools

중요 참고사항: WRITER는 한 번에 하나의 WRITER tool(translation, graph, web_search, llm, image, vision)만 바인딩할 수 있습니다. 여러 WRITER tool을 동시에 바인딩할 수 없습니다. 그러나 하나의 WRITER tool과 함께 여러 custom function tool을 바인딩할 수 있습니다.
# ✅ Correct: One WRITER tool + multiple function tools
llm_with_tools = chat.bind_tools(
    [graph_tool, get_supercopa_trophies_count, GetWeather, get_product_info]
)

# ✅ Correct: Different WRITER tool + function tools
llm_with_tools = chat.bind_tools(
    [translation_tool, get_supercopa_trophies_count, GetWeather]
)

# ❌ Incorrect: Multiple WRITER tools (will cause BadRequestError)
llm_with_tools = chat.bind_tools(
    [graph_tool, translation_tool, web_search_tool]  # This will fail
)
다른 WRITER tool을 사용해야 하는 경우 몇 가지 옵션이 있습니다: 옵션 1: 각 대화마다 tool을 다시 바인딩:
# Use graph tool for one conversation
llm_with_tools = chat.bind_tools([graph_tool, get_supercopa_trophies_count])
response1 = llm_with_tools.invoke([HumanMessage("Use the knowledge graph to answer...")])

# Switch to translation tool for another conversation
llm_with_tools = chat.bind_tools([translation_tool, get_supercopa_trophies_count])
response2 = llm_with_tools.invoke([HumanMessage("Translate this text...")])
옵션 2: 별도의 ChatWriter 인스턴스 사용:
# Create separate ChatWriter instances for different tools
chat_with_graph = ChatWriter()
llm_with_graph_tool = chat_with_graph.bind_tools([graph_tool])

chat_with_translation = ChatWriter()
llm_with_translation_tool = chat_with_translation.bind_tools([translation_tool])

Invocation

모델은 모든 모드(streaming/non-streaming, sync/async)에서 호출 중에 자동으로 tool을 선택합니다.
from langchain.messages import HumanMessage

# Example with graph tool and function tools
llm_with_tools = chat.bind_tools([graph_tool, get_supercopa_trophies_count])
messages = [
    HumanMessage(
        "Use knowledge graph tool to compose this answer. Tell me what the first line of documents stored in your KG. Also I want to know: how many SuperCopa trophies have Barcelona won?"
    )
]

response = llm_with_tools.invoke(messages)
messages.append(response)

# Example with translation tool
llm_with_translation = chat.bind_tools([translation_tool])
translation_messages = [
    HumanMessage("Translate 'Hello, world!' to Spanish")
]

translation_response = llm_with_translation.invoke(translation_messages)
print(translation_response.content)  # Output: "¡Hola, mundo!"

# Example with web search tool
llm_with_search = chat.bind_tools([web_search_tool])
search_messages = [
    HumanMessage("What are the latest developments in AI technology? Please search the web for current information.")
]

search_response = llm_with_search.invoke(search_messages)
print(search_response.content)  # Output: Current AI developments based on web search
function tool의 경우 tool call 요청이 포함된 assistant 메시지를 받게 됩니다.
print(response.tool_calls)
그런 다음 tool call 요청을 수동으로 처리하고 모델에 전송하여 최종 응답을 받을 수 있습니다:
for tool_call in response.tool_calls:
    selected_tool = {
        "get_supercopa_trophies_count": get_supercopa_trophies_count,
    }[tool_call["name"].lower()]
    tool_msg = selected_tool.invoke(tool_call)
    messages.append(tool_msg)

response = llm_with_tools.invoke(messages)
print(response.content)
GraphTool의 경우 모델이 원격으로 호출하고 graph_data 키 아래의 additional_kwargs에 사용 정보를 반환합니다:
print(response.additional_kwargs["graph_data"])
content 속성에는 최종 응답이 포함됩니다:
print(response.content)

Chaining

WRITER Graph tool은 다른 tool과 다르게 작동합니다. 사용될 때 WRITER 서버가 자동으로 Knowledge Graph 호출 및 RAG를 사용한 응답 생성을 처리합니다. 이러한 자동화된 서버 측 처리로 인해 GraphTool을 독립적으로 호출하거나 LangChain chain의 일부로 사용할 수 없습니다. 위의 예제에서 보여준 것처럼 GraphToolChatWriter 인스턴스와 직접 사용해야 합니다.

API reference

모든 GraphTool 기능 및 구성에 대한 자세한 문서는 API reference를 참조하세요.
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I