---
sidebar:
  hidden: true
title: roboto.ai.agent.subject
---
## Module Contents

### goal_subject()

```python
def roboto.ai.agent.subject.goal_subject(
    goal: roboto.ai.goals.types.AgentGoal,
) -> tuple[roboto.ai.agent.record.AgentSubject, str]
```

`from roboto.ai.agent.subject import goal_subject`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/ai/agent/subject.py#L145-L166)

Return the kind of resource `goal` acts on and the ID of that resource, as the goal writes it.

Roboto calls this when a thread receives goals, to record the dataset or session each goal acts on. The ID is the goal's `dataset_id` or `session_id` as written, so in an agent's request template it may be a `{{name}}` placeholder.

**Parameters**

- **goal** (`roboto.ai.goals.types.AgentGoal`): Goal of any type in [`AgentGoal`](/docs/reference/python-sdk/roboto/ai/goals/types#roboto.ai.goals.types.AgentGoal).

**Returns**

- `tuple[roboto.ai.agent.record.AgentSubject, str]`: `(subject, subject_id)`: the kind of resource the goal acts on and the goal's `dataset_id` or `session_id`.

### infer_agent_subject()

```python
def roboto.ai.agent.subject.infer_agent_subject(
    request_template: roboto.ai.agent_thread.record.StartAgentThreadRequest,
    variables: collections.abc.Sequence[roboto.ai.agent.record.TemplateVariable],
) -> Optional[roboto.ai.agent.record.AgentSubject]
```

`from roboto.ai.agent import infer_agent_subject`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/ai/agent/subject.py#L36-L74)

Return the kind of resource an agent is launched on, worked out from its goals and variables.

Roboto calls this when it returns an agent, and sets [`subject`](/docs/reference/python-sdk/roboto/ai/agent/record#roboto.ai.agent.record.AgentRecord.subject) to the result.

An agent with goals takes the subject of its first goal: every goal acts on a dataset or on a session, and `validate_agent_subject` rejects an agent whose goals disagree. An agent without goals is launched on a dataset when one of its variables has type [`DATASET_ID`](/docs/reference/python-sdk/roboto/ai/agent/record#roboto.ai.agent.record.TemplateVariableType.DATASET_ID) and none has type `SESSION_ID`, and on a session in the reverse case.

**Parameters**

- **request_template** (`roboto.ai.agent_thread.record.StartAgentThreadRequest`): Request that starts each of the agent's threads.
- **variables** (`collections.abc.Sequence[roboto.ai.agent.record.TemplateVariable]`): Variables of the agent.

**Returns**

- `Optional[roboto.ai.agent.record.AgentSubject]`: Subject of the agent, or `None` when it has none: the agent has no goals, and its variables include both a dataset ID and a session ID, or neither.

**Usage**

```python
from roboto.ai.agent import TemplateVariable, TemplateVariableType, infer_agent_subject
from roboto.ai.agent_thread import StartAgentThreadRequest
from roboto.ai.goals import SessionSummaryAgentGoal
template = StartAgentThreadRequest(goals=[SessionSummaryAgentGoal(session_id="{{session.id}}")])
variables = [TemplateVariable(name="session.id", type=TemplateVariableType.SESSION_ID)]
infer_agent_subject(template, variables)
# <AgentSubject.SESSION: 'session'>
```

### validate_agent_subject()

```python
def roboto.ai.agent.subject.validate_agent_subject(
    request_template: roboto.ai.agent_thread.record.StartAgentThreadRequest,
    variables: collections.abc.Sequence[roboto.ai.agent.record.TemplateVariable],
) -> None
```

`from roboto.ai.agent.subject import validate_agent_subject`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/ai/agent/subject.py#L77-L112)

Reject an agent whose goals mix datasets and sessions, or whose goal IDs name the wrong kind of variable.

Roboto calls this when an agent is created or updated. An agent is launched on either a dataset or a session, so all of its goals must act on the same kind of resource. A goal's `dataset_id` or `session_id` must be a literal ID, which pins the agent to one dataset or session, or exactly one `{{name}}` placeholder naming a variable of the matching type: [`DATASET_ID`](/docs/reference/python-sdk/roboto/ai/agent/record#roboto.ai.agent.record.TemplateVariableType.DATASET_ID) or `SESSION_ID`. A placeholder that names no variable of the agent passes this check; building [`AgentRecord`](/docs/reference/python-sdk/roboto/ai/agent/record#roboto.ai.agent.record.AgentRecord) rejects it.

**Parameters**

- **request_template** (`roboto.ai.agent_thread.record.StartAgentThreadRequest`): Request that starts each of the agent's threads.
- **variables** (`collections.abc.Sequence[roboto.ai.agent.record.TemplateVariable]`): Variables of the agent.

**Raises**

- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): The goals act on both datasets and sessions, or a goal's `dataset_id` or `session_id` embeds a placeholder in other text or names a variable of the wrong type.

**Returns**

- `None`
