Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CrewAIInc CrewAI ContextualAI Create Agent Tool

From Leeroopedia
Knowledge Sources
Domains Tools, RAG, ContextualAI
Last Updated 2026-02-11 00:00 GMT

Overview

Concrete tool for creating Contextual AI RAG agents with documents and datastores provided by CrewAI.

Description

The ContextualAICreateAgentTool class extends BaseTool to orchestrate the creation of complete RAG pipelines on the Contextual AI platform. During initialization, it creates a ContextualAI client using the provided api_key and requires the contextual-client package. The _run method executes a three-step pipeline: first, it creates a datastore via contextual_client.datastores.create; second, it uploads documents from local file paths to the datastore via contextual_client.datastores.documents.ingest; third, it creates an agent linked to the datastore via contextual_client.agents.create. Returns a success message containing the agent ID, datastore ID, and document count, or an error message on failure.

Usage

Use this tool when CrewAI agents need to programmatically set up domain-specific RAG agents with custom document collections on the Contextual AI platform.

Code Reference

Source Location

  • Repository: CrewAI
  • File: lib/crewai-tools/src/crewai_tools/tools/contextualai_create_agent_tool/contextual_create_agent_tool.py
  • Lines: 1-81

Signature

class ContextualAICreateAgentTool(BaseTool):
    name: str = "Contextual AI Create Agent Tool"
    description: str = "Create a new Contextual AI RAG agent with documents and datastore"
    args_schema: type[BaseModel] = ContextualAICreateAgentSchema
    api_key: str
    contextual_client: Any = None

    def __init__(self, **kwargs): ...
    def _run(self, agent_name: str, agent_description: str,
             datastore_name: str, document_paths: list[str]) -> str: ...

Import

from crewai_tools import ContextualAICreateAgentTool

I/O Contract

Inputs

Name Type Required Description
api_key str Yes Contextual AI API key (constructor)
agent_name str Yes Name for the new agent
agent_description str Yes Description for the new agent
datastore_name str Yes Name for the new datastore
document_paths list[str] Yes List of local file paths to upload as documents

Outputs

Name Type Description
_run() returns str Success message with agent ID, datastore ID, and document count, or error message

Usage Examples

Basic Usage

from crewai_tools import ContextualAICreateAgentTool

tool = ContextualAICreateAgentTool(api_key="your-api-key")
result = tool.run(
    agent_name="My RAG Agent",
    agent_description="Agent for technical documentation",
    datastore_name="tech-docs-store",
    document_paths=["./docs/guide.pdf", "./docs/api-ref.pdf"]
)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment