Skip to main content

AI Search API integration for CrewAI - Enable intelligent web search in your crews

Project description

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 systemuser in your context.
  • API key errors → Check AISEARCH_API_KEY is set correctly in your environment.

License

MIT License - see the LICENSE file.


Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crewai_aisearchapi-1.0.8.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

crewai_aisearchapi-1.0.8-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file crewai_aisearchapi-1.0.8.tar.gz.

File metadata

  • Download URL: crewai_aisearchapi-1.0.8.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for crewai_aisearchapi-1.0.8.tar.gz
Algorithm Hash digest
SHA256 65f7bfe24736d85afec8dda25ca9d3854c1fb708e127d7ebab89e577718dce5e
MD5 3a3090f09ee452cd292a538575cd073a
BLAKE2b-256 51eb93eb8e25205e9082112dbff6286377f3cd73cd397bd2236e2cf546849f3d

See more details on using hashes here.

File details

Details for the file crewai_aisearchapi-1.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for crewai_aisearchapi-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 fc351ac3ad30cccf9cbd260cac76c766e431c23b9cdea1f43089e916aaf77601
MD5 f39129008f55c4480a3bba6cdf3dd4fb
BLAKE2b-256 bd23ffd9081b3003751e99717b6bb4173d65eaf6e26297db18b1b1ff849d40a8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page