LangChain Tool

LangChain Tool

LangChainTool은 LangChain 도구와 쿼리 엔진을 위한 래퍼(wrapper)예요.

출처: 문서

본문

LangChainTool

CrewAI는 LangChain이 제공하는 방대한 도구 목록과 매끄럽게 통합되며, 이 모든 도구를 CrewAI와 함께 사용할 수 있어요.

import os
from dotenv import load_dotenv
from crewai import Agent, Task, Crew
from crewai.tools import BaseTool
from pydantic import Field
from langchain_community.utilities import GoogleSerperAPIWrapper

# Set up your SERPER_API_KEY key in an .env file, eg:
# SERPER_API_KEY=<your api key>
load_dotenv()

search = GoogleSerperAPIWrapper()

class SearchTool(BaseTool):
    name: str = "Search"
    description: str = "Useful for search-based queries. Use this to find current information about markets, companies, and trends."
    search: GoogleSerperAPIWrapper = Field(default_factory=GoogleSerperAPIWrapper)

    def _run(self, query: str) -> str:
        """Execute the search query and return results"""
        try:
            return self.search.run(query)
        except Exception as e:
            return f"Error performing search: {str(e)}"

# Create Agents
researcher = Agent(
    role='Research Analyst',
    goal='Gather current market data and trends',
    backstory="""You are an expert research analyst with years of experience in
    gathering market intelligence. You're known for your ability to find
    relevant and up-to-date market information and present it in a clear,
    actionable format.""",
    tools=[SearchTool()],
    verbose=True
)

# rest of the code ...

결론 (Conclusion)

도구는 CrewAI 에이전트의 능력을 확장하고, 넓은 범위의 태스크를 수행하며 효과적으로 협업할 수 있게 하는 핵심 요소예요. CrewAI로 솔루션을 만들 때는 커스텀 도구와 기존 도구를 모두 활용해서 에이전트를 강화하고 AI 생태계를 향상시키세요. 에러 처리, 캐싱 메커니즘, 그리고 도구 인자의 유연성을 고려해 에이전트의 성능과 능력을 최적화하는 것도 좋습니다.

더 알아보기 (Learn more)