from langchain.tools import tool def get_retrieve_book_context_rag_agent_tool(agent): @tool( "Computer science knowledge retriever", description="Used to retrieve computer science related context and answer the request." ) def retrieve_book_context_rag_agent(query: str) -> str: """Delegate the retrieve query context to the agent. Args: query: the full query of th user """ result = agent.invoke({ "messages": [{"role": "user", "content": query}] }) return result["messages"][-1].text return retrieve_book_context_rag_agent