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

# Python

> Track any AI interaction with begin() / end()

## Install

<CodeGroup>
  ```bash pip theme={null}
  pip install agnost
  ```

  ```bash uv theme={null}
  uv add agnost
  ```
</CodeGroup>

## Integrate

```python theme={null}
import agnost

agnost.init("your-org-id")
```

Get your org ID from [app.agnost.ai](https://app.agnost.ai).

## Track interactions

```python theme={null}
interaction = agnost.begin(user_id="u-123", agent_name="my-agent", input="...")
# ... your AI call ...
interaction.end(output="...")
```

Latency is auto-calculated. For errors:

```python theme={null}
interaction.end(output="Error: timeout", success=False)
```

For simple fire-and-forget cases:

```python theme={null}
agnost.track(user_id="u-123", input="...", output="...", agent_name="my-agent")
```

## Group into conversations

```python theme={null}
import uuid

conversation_id = str(uuid.uuid4())

agnost.track(user_id="u-123", input="Hello", output="Hi!", conversation_id=conversation_id)
agnost.track(user_id="u-123", input="Follow-up", output="Sure!", conversation_id=conversation_id)
```

## Identify users

```python theme={null}
agnost.identify("u-123", {"plan": "pro", "role": "admin"})
```

## Custom properties

```python theme={null}
interaction = agnost.begin(user_id="u-123", agent_name="my-agent", input="...")

# Set one at a time
interaction.set_property("model", "gpt-4")

# Or set many at once
interaction.set_properties({"tokens": 150, "cost": 0.045})

interaction.end(output="...")
```

## Configuration

```python theme={null}
agnost.init("your-org-id", endpoint="https://api.agnost.ai", debug=True)
```

| Parameter | Type | Default | Description |
| - | - | - | - |
| `org_id` | `str` | — | Your org ID |
| `endpoint` | `str` | `https://api.agnost.ai` | API endpoint |
| `debug` | `bool` | `False` | Enable debug logging |

## Cleanup

```python theme={null}
agnost.shutdown()  # flushes and cleans up
```

## What appears in Agnost AI

* **Conversations** grouped by `conversation_id`.
* **User-level analytics** grouped by `user_id`.
* **Events** for every tracked interaction.
* Unsuccessful interactions remain visible in **Events** with `success=False`.

## Verify

Run one `begin()` / `end()` interaction, then open [app.agnost.ai](https://app.agnost.ai). Check **Events** first, then **Conversations**.

## Troubleshooting

* Confirm `agnost.init("your-org-id")` runs before tracking.
* Call `agnost.flush()` or `agnost.shutdown()` before short-lived scripts exit.
* Confirm the endpoint is `https://api.agnost.ai` unless you intentionally use another endpoint.

## Next steps

* [Conversations](/using-conversations): review how Python interactions are grouped.
* [Events](/using-events): inspect the exact records the SDK sent.
* [Intents](/using-intents): organize production conversations by what users wanted.


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