Skip to main content

AI Search API for CrewAI - Contextual Prompts Guide

PyPI version Python Support License: MIT

A Python integration for CrewAI that connects your agents to the AI Search API.
It enables contextual prompts, multi-message context handling, and intelligent answers with source citations.

👉 Get your free API key from the AI Search API dashboard.


Features

  • 🔍 Prompt + Context Search: Send a query plus structured context for better results
  • 💬 Multi-Message Context: Pass multiple user messages for conversational awareness
  • 📚 Sources Included: Responses come with citations when available
  • ⚡ CrewAI Integration: Works with Agent, Task, Crew out of the box
  • 🖥️ Works with Local LLMs: Use Ollama for reasoning + the search API for live info
  • 🛡️ Robust Error Handling: Clear exceptions when context roles or models are invalid

Installation

pip install crewai-aisearchapi

Quick Start (with Ollama + CrewAI)

from crewai import Agent, Task, Crew, Process, LLM
from crewai_aisearchapi import AISearchTool

llm = LLM(
    model="ollama/llama3.2:3b",          # use a local model
    base_url="http://localhost:11434",   # Ollama default
    temperature=0.2,
)

tool = AISearchTool(api_key="your-api-key")

agent = Agent(
    role="Researcher",
    goal="Answer questions with context and sources.",
    backstory="Careful and concise.",
    tools=[tool],
    llm=llm,
    verbose=True,
)

task = Task(
    description="Answer: '{question}'. Keep it short.",
    expected_output="2–4 sentences.",
    agent=agent,
    markdown=True,
)

crew = Crew(agents=[agent], tasks=[task], process=Process.sequential, verbose=True)

if __name__ == "__main__":
    print(crew.kickoff(inputs={"question": "What is RLHF in AI?"}))

Contextual Prompts

The AI Search API is designed to handle context-rich prompts.
All context messages must use "role": "user".

result = tool.run({
    "prompt": "Explain how RLHF improves AI safety.",
    "context": [
        {"role": "user", "content": "Keep it simple, I'm new to ML."},
        {"role": "user", "content": "Add one practical example."}
    ],
    "response_type": "markdown"
})

This produces an answer that considers both your question and the context messages.


Configuration Options

from crewai_aisearchapi import AISearchTool, AISearchToolConfig

config = AISearchToolConfig(
    default_response_type="markdown",
    include_sources=True,
    timeout=30,
    verbose=True
)

tool = AISearchTool(api_key="your-api-key", config=config)

Handling Responses

The tool returns a formatted string containing:

  • Answer (the AI response)
  • Sources (when available)
  • Response Time

Example:

Reinforcement Learning with Human Feedback (RLHF) helps align AI models with human intent...

**Sources:**
- [1] https://example.com/rlhf-overview
- [2] https://research.example.org/rlhf

*Response time: 120ms*

Environment Variables

export AISEARCH_API_KEY="your-api-key"

In Python:

import os
from crewai_aisearchapi import AISearchTool

tool = AISearchTool(api_key=os.getenv("AISEARCH_API_KEY"))

Troubleshooting

  • model not found → Ensure you pulled the Ollama model:
    ollama pull llama3.2:3b
  • Each context message must have role "user" → Convert system → user in your context.
  • API key errors → Check AISEARCH_API_KEY is set correctly in your environment.

License

MIT License - see the LICENSE file.


Support

Metadata

Release files for crewai-aisearchapi 1.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crewai-aisearchapi 1.0.8
File Size Uploaded Provenance Actions
crewai_aisearchapi-1.0.8.tar.gz 7.7 kB Without provenance Details for crewai_aisearchapi-1.0.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for crewai-aisearchapi 1.0.8
File Interpreter ABI Platform Actions
crewai_aisearchapi-1.0.8-py3-none-any.whl Python 3 none any Details for crewai_aisearchapi-1.0.8-py3-none-any.whl

Total release size: 15.4 kB

Release files / crewai_aisearchapi-1.0.8.tar.gz

Download URL crewai_aisearchapi-1.0.8.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
65f7bfe24736d85afec8dda25ca9d3854c1fb708e127d7ebab89e577718dce5e
BLAKE2b-256 checksum
How to use checksums
51eb93eb8e25205e9082112dbff6286377f3cd73cd397bd2236e2cf546849f3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / crewai_aisearchapi-1.0.8-py3-none-any.whl

Download URL crewai_aisearchapi-1.0.8-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc351ac3ad30cccf9cbd260cac76c766e431c23b9cdea1f43089e916aaf77601
BLAKE2b-256 checksum
How to use checksums
bd23ffd9081b3003751e99717b6bb4173d65eaf6e26297db18b1b1ff849d40a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for crewai-aisearchapi 1.0.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page