Build a ReAct Search Agent in Python with Prismfy
ai agentsweb search apitool callingfresh web contextagent workflowprismfy

Build a ReAct Search Agent in Python with Prismfy

Build a ReAct Search Agent in Python with Prismfy for fresh public-web evidence.

P

Prismfy Team

May 7, 2026

5 min read

Build a ReAct Search Agent in Python with Prismfy

This guide shows a practical way to use Prismfy as a live web search API inside an agent workflow so your assistant can fetch fresh public evidence instead of relying on stale model memory.

Problem framing

ReAct works well because it separates thinking from acting. The model reasons about what to do next, then takes a tool action, then reasons again with the new evidence. That structure is especially useful when the answer may be hidden in a public page that changes over time.

The weak point is the tool layer. If the search step is slow to build or too vague, the whole agent becomes noisy. Prismfy gives the agent a clean public-web search primitive: send a question, get structured results, and keep the loop moving.

Why this matters now

Many Python agents still pretend that retrieval is a one-time setup problem. It is not. Freshness is a runtime requirement. A launch post, a docs edit, or a pricing change can invalidate a previously cached answer immediately.

For a ReAct agent, that means search should be first-class. It should be callable, cheap to reason about, and easy to scope. Prismfy fits that slot because it exposes one predictable endpoint and returns the kind of structured response a ReAct loop can inspect without extra parsing.

Step-by-step solution

  1. Define the agent state. Track the user question, the latest search query, the retrieved evidence, and the final answer.
  2. Make the policy explicit. Search when the request depends on current public information, a specific domain, or a source the agent has not seen before.
  3. Call Prismfy from a Python helper. Use POST /v1/search with query, and add domain or timeRange when the task needs a tighter scope.
  4. Compress the search results. Keep titles, URLs, and short snippets. ReAct loops work better when the evidence is concise.
  5. Let the model decide whether to search again. If the first query is too broad, the agent should refine it rather than forcing an answer.

Code example

The code below shows a minimal ReAct-style loop in Python. It does not depend on a framework. You can drop the search helper into LangChain, LangGraph, or a custom orchestrator later.

import os
import requests
from dataclasses import dataclass, field

PRISMFY_URL = "https://api.prismfy.io/v1/search"

@dataclass
class AgentState:
    question: str
    thoughts: list[str] = field(default_factory=list)
    evidence: list[dict] = field(default_factory=list)
    answer: str | None = None

def prismfy_search(query: str, domain: str | None = None, time_range: str | None = "month"):
    payload = {
        "query": query,
        "page": 1,
    }
    if domain:
        payload["domain"] = domain
    if time_range:
        payload["timeRange"] = time_range

    res = requests.post(
        PRISMFY_URL,
        headers={
            "Authorization": f"Bearer {os.environ['PRISMFY_API_KEY']}",
            "Content-Type": "application/json",
        },
        json=payload,
        timeout=30,
    )
    res.raise_for_status()
    return res.json()

def summarize_results(search_json, limit=4):
    out = []
    for item in search_json["results"][:limit]:
        out.append({
            "title": item["title"],
            "url": item["url"],
            "snippet": item["content"][:260],
            "engine": item["engine"],
        })
    return out

def react_step(state: AgentState):
    if not state.evidence:
        query = f"{state.question} latest public web"
        search_json = prismfy_search(query)
        state.evidence = summarize_results(search_json)
        state.thoughts.append("Search first because the question depends on current public information.")
        return state

    # Replace this with your model call.
    state.answer = (
        "Answer from evidence only. "
        "Cite the strongest URLs and mention uncertainty if the results are weak."
    )
    return state

if __name__ == "__main__":
    state = AgentState(question="What changed on the product page this month?")
    state = react_step(state)
    print(state.evidence)

In a real ReAct prompt, the model should see a short instruction like: search when the answer may be stale, ask for a narrower query if the first pass is noisy, and never answer from memory when the evidence clearly matters. That policy keeps the loop honest.

Practical notes and caveats

The most common mistake is letting the agent search too often. ReAct is not an excuse to call search on every turn. Use search only when the question depends on current public data, and keep the result set small enough that the model can actually reason over it.

The second mistake is overfitting to a single query format. If the question is about a specific company or docs site, add domain. If recency matters, add timeRange. If neither matters, keep the query broad and let the model refine on the next step.

Prismfy response caching can help with repeated questions, but you should still treat the search step as live evidence. That is the right mental model for a ReAct agent.

Why Prismfy fits this workflow

Prismfy fits ReAct because it is simple to call, returns structured JSON, and aligns with the agent's decision loop. The agent reasons, searches, reasons again, and answers with the latest public context it can actually see.

That is the practical version of agentic search: not more abstraction, just better runtime evidence.

FAQ

When should an agent call web search instead of answering from memory?

Use live search when the task depends on current public information such as pricing pages, release notes, launch posts, or documentation updates. That is the safest time to route the agent workflow through Prismfy instead of relying on model memory alone.

Can Prismfy work as a tool inside an agent loop?

Yes. Prismfy is easiest to use as a runtime search step: the agent decides a question is time-sensitive, calls POST /v1/search, trims the returned evidence, and answers from those public sources.

Related Prismfy guides

Try Prismfy

Create a Prismfy key, test POST /v1/search, and wire the search step into the workflow you care about first.

Try it free

Add real-time web search to your AI

Free tier includes 3,000 requests per 30 days. No credit card required.