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

# استخراج JSON منظّم باستخدام Python Agent SDK

> استخدم Python Agent SDK في دورة محدودة بأداة محلية تُرجع JSON صارمًا عبر Phaseo Gateway.

استخدم هذه الوصفة عندما يحتاج سير عمل Python إلى:

* أداة بحث محلية واحدة
* دورة وكيل محدودة واحدة
* بنية إخراج JSON صارمة واحدة

## 1. جهّز حزم SDK

<Note type="warning">لم تُنشر حزمة Python Agent SDK على PyPI بعد. اتبع [تعليمات التثبيت من المصدر](../sdk-reference/python/agent-sdk-installation.mdx).</Note>

## 2. عرّف أداة محلية

```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. أنشئ الوكيل

```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. شغّل الوكيل عبر عميل البوابة

```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. متى تناسب هذه الوصفة

* يتولى عامل Python واحد التنسيق
* تكون الأدوات محلية وحتمية
* تريد إخراجًا صارمًا قبل إنشاء طبقة تنسيق أوسع

## مواضيع ذات صلة

* [Python Agent SDK](../sdk-reference/python/agent-sdk.mdx)
* [إخراج JSON منظّم من Python](./sdk-python-presets-and-json.mdx)


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