Agent Mode  ·  X Research (EN + 日本語)  ·  Planet Intelligence  ·  session_id

Slopshop for
Grok & xAI Agents

Built with Grok's feedback. Real compute. Free memory. Planet Research.
Grok/X powers English and Japanese X intelligence in Planet Research — the most advanced research system on the internet, synthesizing across 5 global providers.

X+JP
Bilingual X Search
Agent
Mode Native
0cr
Memory Cost
🌎
Planet Research

Quickstart

Three steps. Grok is in Agent Mode.

Enable Agent Mode with one header. Add a session_id for persistent memory across calls. The enhanced response envelope handles the rest automatically.

Step 01 — Install

pip install slopshop

The Slopshop client handles the xAI-compatible request format, session management, and the Agent Mode response envelope automatically.

pip install slopshop
Step 02 — Enable Agent Mode

Add X-Agent-Mode: grok

Set the header on every request. Slopshop returns the enhanced envelope with suggestions, cache_fingerprint, and auto-persisted memory.

X-Agent-Mode: grok
Step 03 — Persist State

Add session_id for memory

Pass a session_id in the request body. Slopshop automatically saves tool results to that session's memory namespace — no extra calls needed.

"session_id": "grok-{uuid}" → auto-persist

Agent Mode Headers

X-Agent-Mode request headers

Three headers control how Slopshop behaves in Grok's Agent Mode. Each unlocks a different part of the enhanced response envelope.

X-Agent-Mode: grok Enables enhanced response envelope with suggestions + fingerprint
X-Session-Id: sess_grok_a1b2c3d4 Binds this call to a persistent memory namespace — results auto-saved
X-Auto-Persist: true Automatically write tool output to session memory (no memory-set call needed)

Or pass mode="grok" and session_id in the request body — headers and body params are interchangeable.


Enhanced Response Envelope

Standard mode vs. Agent Mode responses

Agent Mode returns a richer envelope. suggestions tells Grok what to do next. cache_fingerprint lets Grok skip re-fetching. persisted confirms memory was written.

Standard response (no Agent Mode)
{
  "valid": true,
  "expires": "2026-09-12",
  "issuer": "Let's Encrypt",
  "days_left": 170,
  "_engine": "real"
}
Agent Mode response (X-Agent-Mode: grok)
{
  "valid": true,
  "expires": "2026-09-12",
  "issuer": "Let's Encrypt",
  "days_left": 170,
  "_engine": "real",
  "_agent": {
    "mode": "grok",
    "session_id": "sess_grok_a1b2c3d4",
    "persisted": true,
    "cache_fingerprint": "sha256:9f3a...",
    "suggestions": [
      "check dns-lookup for this host",
      "run http-request to verify HSTS"
    ],
    "credits_used": 2
  }
}

Working Code Example

Grok + Slopshop: Agent Mode with session memory

Complete example using the xAI-compatible API. Agent Mode enabled, session_id for persistence, enhanced envelope for Grok's multi-step reasoning.

grok_agent.py — Agent Mode with persistent session python
# Slopshop + Grok: Agent Mode with session persistence
# Uses xAI-compatible request format + enhanced response envelope

import os, json, uuid, requests
from openai import OpenAI  # xAI API is OpenAI-compatible

# xAI client (Grok)
grok = OpenAI(
    api_key=os.environ["XAI_API_KEY"],
    base_url="https://api.x.ai/v1"
)

SLOP_KEY    = os.environ["SLOPSHOP_API_KEY"]
SLOP_URL    = "https://slopshop.gg"
SESSION_ID  = f"sess_grok_{uuid.uuid4().hex[:12]}"


def call_slopshop_agent(tool_name: str, args: dict) -> dict:
    """Call Slopshop in Agent Mode — returns enhanced envelope."""
    slug = tool_name.replace("_", "-")
    resp = requests.post(
        f"{SLOP_URL}/v1/{slug}",
        headers={
            "Authorization":  f"Bearer {SLOP_KEY}",
            "Content-Type":    "application/json",
            "X-Agent-Mode":    "grok",          # Enable Agent Mode
            "X-Session-Id":    SESSION_ID,           # Bind to session
            "X-Auto-Persist":  "true"              # Auto-save to memory
        },
        json={**args, "session_id": SESSION_ID, "mode": "grok"}
    )
    result = resp.json()

    # Log what Agent Mode gave us
    if agent_meta := result.get("_agent"):
        print(f"  [agent] persisted={agent_meta['persisted']}")
        print(f"  [agent] fingerprint={agent_meta['cache_fingerprint'][:16]}...")
        if agent_meta.get("suggestions"):
            print(f"  [agent] suggestions: {agent_meta['suggestions']}")

    return result


def run_grok_agent(task: str) -> str:
    """Run Grok in Agent Mode with Slopshop tools."""
    # Fetch tools as OpenAI-compatible function definitions
    tools_resp = requests.get(
        f"{SLOP_URL}/v1/openapi.json",
        headers={"Authorization": f"Bearer {SLOP_KEY}"}
    )
    # ... (convert to OpenAI tool format, see integrate-openai.html)

    messages = [{"role": "user", "content": task}]
    print(f"Session: {SESSION_ID}")

    while True:
        response = grok.chat.completions.create(
            model="grok-3",
            messages=messages,
            tools=tools,           # Slopshop tools
            tool_choice="auto"
        )
        msg = response.choices[0].message
        messages.append(msg)

        if msg.tool_calls:
            for tc in msg.tool_calls:
                print(f"Grok calling: {tc.function.name}")
                result = call_slopshop_agent(
                    tc.function.name,
                    json.loads(tc.function.arguments)
                )
                messages.append({
                    "role": "tool",
                    "tool_call_id": tc.id,
                    "content": json.dumps(result)
                })
        else:
            return msg.content


# All tool results are auto-persisted to SESSION_ID memory namespace
answer = run_grok_agent(
    "Audit api.x.ai — DNS records, SSL cert grade, and HTTP security headers"
)
print(answer)

What You Get

82 categories of tools built for how Grok thinks

Grok's Agent Mode is designed for multi-step autonomous execution. Slopshop is the execution layer that makes each step real.

🀅

78 Categories of Real Tools

DNS, SSL, HTTP, crypto, code execution, data transforms, document generation. All real compute. _engine: "real" on every response.

🧠

Free Persistent Memory

Session-scoped memory with session_id. Auto-persist writes tool results to memory without extra API calls. Free tier never expires.

Agent Mode Native

Enhanced response envelope with suggestions, cache_fingerprint, and auto-persist. Built specifically for Grok's agentic flow.

👀

Full Observability

Audit logs, per-session tracing, credit usage per tool call. Every tool Grok calls is logged with the session_id, inputs, outputs, and latency.

🏠

Self-Hostable

Run Slopshop on your infrastructure. Zero external dependencies. Air-gapped environments supported. Same Agent Mode envelope.


The tool layer Grok helped design

Built with Grok's feedback. Real compute. Free memory. Agent Mode native.
Set X-Agent-Mode: grok and watch the enhanced envelope appear.

Read the Docs Browse Curated Tools Browse Browse All Tools
→ Full Docs → Browse Tools → Agent Templates → Savings Calculator