# create_sub_agent

> **Function** in `deepagents`

📖 [View in docs](https://reference.langchain.com/python/deepagents/middleware/subagents/create_sub_agent)

Create a runnable agent from a raw `SubAgent` spec.

This is the shared entrypoint for the `create_agent` path used by
raw subagent specs. Pre-compiled `CompiledSubAgent` runnables are already
created by the caller and are handled separately by `SubAgentMiddleware`.

## Signature

```python
create_sub_agent(
    spec: SubAgent,
    *,
    state_schema: type | None = None,
    response_format: ResponseFormat[Any] | type | dict[str, Any] | None = None,
) -> Runnable
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `spec` | `SubAgent` | Yes | Subagent spec to compile. Must specify `model` and `tools`. |
| `state_schema` | `type \| None` | No | Base graph state schema forwarded to `create_agent` for the subagent. (default: `None`) |
| `response_format` | `ResponseFormat[Any] \| type \| dict[str, Any] \| None` | No | Optional response format override for this compiled subagent instance. (default: `None`) |

## Returns

`Runnable`

Runnable agent ready for task-tool invocation.

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/7e70065200007896336f38fe905803e6763e8f85/libs/deepagents/deepagents/middleware/subagents.py#L459)