> ## Documentation Index
> Fetch the complete documentation index at: https://phaseo.app/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Strukturiertes JSON mit dem Python Agent SDK extrahieren

> Nutze das Python Agent SDK für einen begrenzten Ablauf mit lokalem Tool, der über Phaseo Gateway striktes JSON zurückgibt.

Verwende dieses Rezept, wenn ein Python-Ablauf Folgendes benötigt:

* ein lokales Such-Tool
* einen begrenzten Agent-Ablauf
* eine strikte JSON-Ausgabeform

## 1. SDKs vorbereiten

<Note type="warning">Das Python Agent SDK ist noch nicht auf PyPI verfügbar. Folge der [Installationsanleitung aus dem Quellcode](../sdk-reference/python/agent-sdk-installation.mdx).</Note>

## 2. Ein lokales Tool definieren

```python theme={null}
from phaseo_agent import AgentTool, define_tool

lookup_policy = define_tool(
    AgentTool(
        id="lookup-policy",
        description="Look up one internal policy by slug.",
        parameters={
            "type": "object",
            "properties": {
                "slug": {"type": "string"},
            },
            "required": ["slug"],
            "additionalProperties": False,
        },
        execute=lambda input, ctx: {
            "slug": input["slug"],
            "summary": "Presets centralize routing, prompts, and caching defaults.",
        },
    )
)
```

## 3. Agent erstellen

```python theme={null}
from phaseo_agent import create_agent

agent = create_agent(
    {
        "id": "policy-extractor",
        "model": "openai/gpt-5.4-nano",
        "instructions": "Use tools when needed and return concise JSON.",
        "tools": [lookup_policy],
        "parse_output": lambda text: text,
    }
)
```

## 4. Den Agent mit dem Gateway-Client ausführen

```python theme={null}
from phaseo_agent import create_gateway_agent_client

result = agent.run(
    input="Look up presets and return JSON with keys summary and recommendation.",
    client=create_gateway_agent_client(),
)

print(result.output)
```

## 5. Wann dieses Rezept passt

* ein Python-Worker die Orchestrierung übernimmt
* die Tools lokal und deterministisch sind
* du eine strikte Ausgabe möchtest, bevor du eine größere Orchestrierungsschicht aufbaust

## Weiterführende Themen

* [Python Agent SDK](../sdk-reference/python/agent-sdk.mdx)
* [Strukturiertes JSON mit Python ausgeben](./sdk-python-presets-and-json.mdx)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.