query
Answer questions about enterprise knowledge bases using retrieval-augmented generation with context-aware responses and source citations.
Instructions
An enterprise search tool that can answer questions about any sort of knowledge base
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes |
Implementation Reference
- multi-agent/server.py:10-44 (handler)Handler for the 'query' MCP tool. Reranks available agents by relevance to the user prompt and queries the most relevant agent using the ContextualAI client.@mcp.tool() def query(prompt: str) -> str: """An enterprise search tool that can answer questions about any sort of knowledge base""" client = ContextualAI( api_key=API_KEY, # This is the default and can be omitted ) instruction = "Rank documents based on their ability to answer the question/query" agents = {} for agent in client.agents.list(): agents.update({agent.id: f"{agent.name} - {agent.description}"}) documents = list(agents.values()) results = client.rerank.create( model="ctxl-rerank-en-v1-instruct", instruction=instruction, query=prompt, documents=documents, metadata=metadata, top_n=1 ) agent_index = results.results[0].index agent_id = list(agents.keys())[agent_index] query_result = client.agents.query.create( agent_id=agent_id, messages=[{ "content": prompt, "role": "user" }] ) return query_result.message.content
- single_agent/server.py:11-24 (handler)Handler for the 'query' MCP tool. Directly queries a predefined specific agent using the ContextualAI client.@mcp.tool() def query(prompt: str) -> str: """An enterprise search tool that can answer questions about a specific knowledge base""" client = ContextualAI( api_key=API_KEY, # This is the default and can be omitted ) query_result = client.agents.query.create( agent_id=AGENT, messages=[{ "content": prompt, "role": "user" }] ) return query_result.message.content