> ## 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.

# Extraire du JSON structuré avec le SDK Agent Python

> Utilisez le SDK Agent Python dans un cycle limité avec un outil local pour renvoyer du JSON strict via Phaseo Gateway.

Utilisez cette recette lorsqu’un workflow Python a besoin de :

* un outil de recherche local
* un cycle d’agent limité
* une structure de sortie JSON stricte

## 1. Préparer les SDK

<Note type="warning">Le package Python Agent SDK n’est pas encore disponible sur PyPI. Suivez les [instructions d’installation depuis les sources](../sdk-reference/python/agent-sdk-installation.mdx).</Note>

## 2. Définir un outil local

```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. Créer l’agent

```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. Exécuter l’agent avec le client relié à la passerelle

```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. Quand utiliser cette recette

* un worker Python gère l’orchestration
* les outils sont locaux et déterministes
* vous souhaitez une sortie stricte avant de créer une couche d’orchestration plus vaste

## À lire aussi

* [SDK Agent Python](../sdk-reference/python/agent-sdk.mdx)
* [Produire du JSON structuré en Python](./sdk-python-presets-and-json.mdx)


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