Skip to content

Commit 84712a2

Browse files
initial commit
0 parents  commit 84712a2

28 files changed

+1404
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.github/workflows/docs.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Documentation Docker Image
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
7+
jobs:
8+
9+
build:
10+
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Build the Docker image
16+
working-directory: docs
17+
run: docker build . --tag invariant-docs:main
18+
- name: Login to Invariant Container Registry
19+
run: echo ${{ secrets.INVARIANT_REGISTRY_PASSWORD }} | docker login -u ${{ secrets.INVARIANT_REGISTRY_USERNAME }} --password-stdin https://images.invariantnet.com
20+
- name: Rename the Docker image
21+
run: docker tag invariant-docs:main images.invariantnet.com/invariant-docs:main
22+
- name: Push the Docker image
23+
run: docker push images.invariantnet.com/invariant-docs:main

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM python:3.12
2+
3+
# install mkdocs
4+
COPY requirements.txt /tmp
5+
RUN pip install --no-cache-dir -r /tmp/requirements.txt
6+
7+
# build the documentation
8+
COPY . /docs
9+
WORKDIR /docs
10+
11+
RUN mkdocs build --clean
12+
13+
# serve the documentation if DEV_MODE is set, otherwise, serve built documentation
14+
# for prod serving, we copy everything to root/docs/, as this is where the docs are actually served from in the container
15+
CMD if [ "$DEV_MODE" = "true" ]; then mkdocs serve -a 0.0.0.0:8000; else mkdocs build; mkdir -p root; mv site root/docs; cd root; python -m http.server 8000 --bind 0.0.0.0; fi

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Invariant SDK documentation
2+
3+
Documentation for the Invariant SDK.
4+
5+
To locally serve a live version of the documentation, run the following command in this directory:
6+
7+
```bash
8+
docker build -t invariant-docs .
9+
docker run -it -p 8000:8000 -e DEV_MODE=true -v .:/docs/ invariant-docs
10+
```
11+
12+
With `DEV_MODE=true` and the mounted volume, the documentation will reflect changes made to the markdown files in real-time.
13+
14+
For deployment, we build the Docker image and push it to the registry:
15+
16+
The actual documentation can be found in the subfolder `docs/`.

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Client Setup
2+
3+
The SDK exposes a `Client` class. To create an object of this type, you need two variables: the Invariant API endpoint URL and the API key.
4+
5+
## Getting the API Key
6+
Navigate to the <img class='inline-invariant' src="../assets/logo.svg"/> [Invariant Explorer](https://explorer.invariantlabs.ai) and create an account via GitHub Sign-In.
7+
8+
Once you have created an account, go to your [User Settings](https://explorer.invariantlabs.ai/settings) and generate an API key.
9+
10+
Make note of your API key, as you will need it to authenticate your uploads. If you're running in a shell, you can export the API key now as an environment variable:
11+
12+
## Setting Up Environment Variables
13+
14+
Navigate to your shell and export the API key as an environment variable. You can optionally set the API endpoint URL as an environment variable as well, which allows you to use private instances of Explorer.
15+
16+
```bash
17+
export INVARIANT_API_ENDPOINT=https://explorer.invariantlabs.ai
18+
# Add the API key here.
19+
export INVARIANT_API_KEY=YourAPIKey
20+
```
21+
22+
## Creating a Client
23+
24+
In your Python code, you can create a `Client` object. This object will use the environment variables you set up earlier to authenticate your uploads.
25+
26+
```python
27+
from invariant_sdk.client import Client
28+
29+
client = Client()
30+
```
31+
32+
Without parameters, the `Client` object will automatically use the environment variables you set up earlier and the default Explorer instance at `https://explorer.invariantlabs.ai`.
33+
34+
## Overriding Environment Configuration
35+
36+
If you want to override the environment configuration or use a different API key, you can also pass the API endpoint URL and API key as arguments to the `Client` constructor directly.
37+
38+
```python
39+
from invariant_sdk.client import Client
40+
41+
client = Client(
42+
api_url="https://explorer.invariantlabs.ai",
43+
# Add the API key here.
44+
api_key="YourAPIKey",
45+
)
46+
```

docs/Explorer_API/2_traces.md

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# Trace Format
2+
3+
The Explorer supports agent traces made up of sequences of events like messages, tool calls and environment outputs. The required format is compatible with the [OpenAI chat data structure](https://platform.openai.com/docs/api-reference/chat/create) with [function calling](https://platform.openai.com/docs/guides/function-calling) support.
4+
5+
This documents shows pseudo-code based class definitions to specify the format more formally, but trace data is expected to be JSON serialized.
6+
7+
### `Event`
8+
9+
```python
10+
class Event:
11+
role: str
12+
content: Optional[str]
13+
tool_calls: Optional[list[ToolCall]]
14+
```
15+
16+
##### `role` <span class='type'>string</span> <span class='required'/>
17+
18+
The role of the event, e.g., `user`, `assistant`, `system` or something else.
19+
20+
##### `content` <span class='type'>string</span> <span class='optional'/>
21+
22+
The content of the event, e.g., agent reasoning and intermediate results.
23+
24+
##### `tool_calls` <span class='type'>list[ToolCall]</span> <span class='optional'/>
25+
26+
A list of tool calls made by the agent in this event.
27+
28+
29+
> Examples <br/><br/>
30+
Simple Message
31+
```json
32+
{ "role": "user", "content": "Hello, how are you?" }
33+
```
34+
Message with Tool Call
35+
```json
36+
{
37+
"role": "assistant",
38+
"content": "Checking your inbox...",
39+
"tool_calls": [
40+
{
41+
"id": "1",
42+
"type": "function",
43+
"function": {
44+
"name": "get_inbox",
45+
"arguments": {
46+
"n": 10
47+
}
48+
}
49+
}
50+
]
51+
}
52+
```
53+
54+
### `ToolCall`
55+
56+
```python
57+
class ToolCall:
58+
id: str
59+
type: str
60+
function: Function
61+
62+
class Function:
63+
name: str
64+
arguments: dict
65+
```
66+
67+
<!-- * `id (str)`: A unique identifier for the tool call.
68+
* `type (str)`: The type of the tool call, e.g., `function`.
69+
* `function (Function)`: The function call made by the agent.
70+
* `name (str)`: The name of the function called.
71+
* `arguments (Dict[str, Any])`: The arguments passed to the function, encoded as a JSON dictionary. -->
72+
73+
##### `id` <span class='type'>string</span> <span class='required'/>
74+
75+
A unique identifier for the tool call.
76+
77+
##### `type` <span class='type'>string</span> <span class='required'/>
78+
79+
The type of the tool call, e.g., `function`.
80+
81+
##### `function` <span class='type'>Function</span> <span class='required'/>
82+
83+
The function call made by the agent.
84+
85+
* ##### `name` <span class='type'>string</span> <span class='required'/>
86+
87+
The name of the function called.
88+
89+
* ##### `arguments` <span class='type'>dict</span> <span class='required'/>
90+
91+
The arguments passed to the function, encoded as a JSON dictionary.
92+
93+
> Example
94+
```json
95+
{
96+
"id": "1",
97+
"type": "function",
98+
"function": {
99+
"name": "get_inbox",
100+
"arguments": {
101+
"n": 10
102+
}
103+
}
104+
}
105+
```
106+
107+
### `ToolOutput`
108+
109+
A special event type for tool outputs, associated with a previous `ToolCall`.
110+
111+
```python
112+
class ToolOutput(Event):
113+
role: str
114+
content: str
115+
tool_call_id: Optional[str]
116+
```
117+
118+
##### `role` <span class='type'>string</span> <span class='required'/>
119+
120+
The role of the event, e.g., `tool`.
121+
122+
##### `content` <span class='type'>string</span> <span class='required'/>
123+
124+
The content of the tool output, e.g., the result of a function call.
125+
126+
##### `tool_call_id` <span class='type'>string</span> <span class='optional'/>
127+
128+
The identifier of a previous ToolCall that this output corresponds to.
129+
130+
> Example
131+
```json
132+
{
133+
"role": "tool",
134+
"tool_call_id": "1",
135+
"content": "1. Subject: Hello, From: Alice, Date: 2024-01-01, 2. Subject: Meeting, From: Bob, Date: 2024-01-02"
136+
}
137+
```
138+
139+
### Full Trace Example
140+
141+
The format suitable for the Invariant SDK is a list of `Event` objects. Here is an example of a trace with a user asking for their inbox, the assistant fetching the inbox, and the assistant listing the inbox contents.
142+
143+
```json
144+
[
145+
{
146+
"role": "user",
147+
"content": "What's in my inbox?"
148+
},
149+
{
150+
"role": "assistant",
151+
"content": "Here are the latest emails.",
152+
"tool_calls": [
153+
{
154+
"id": "1",
155+
"type": "function",
156+
"function": {
157+
"name": "get_inbox",
158+
"arguments": {}
159+
}
160+
}
161+
]
162+
},
163+
{
164+
"role": "tool",
165+
"tool_call_id": "1",
166+
"content": "1. Subject: Hello, From: Alice, Date: 2024-01-0, 2. Subject: Meeting, From: Bob, Date: 2024-01-02"
167+
},
168+
{
169+
"role": "assistant",
170+
"content": "You have 2 new emails."
171+
}
172+
]
173+
```

docs/Explorer_API/3_annotations.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Annotations
2+
3+
<div class='subtitle'>Learn how to annotate traces in Explorer to add context and structure</div>
4+
5+
In addition to hosting agent traces, Explorer can also be used to annotate traces with additional information, as created in error analysis, human labeling or by other means.
6+
7+
Annotations provide additional context, facilitating collaboration and agent error and security analysis.
8+
9+
<figure class='wide'>
10+
11+
<img src="../assets/annotated-trace.png" alt="An annotated trace" style="width: 100%;">
12+
13+
<figcaption>An annotated trace in Explorer</figcaption>
14+
15+
</figure>
16+
17+
## Annotation Format
18+
19+
You can add annotations to traces at upload time. For this, both during [file upload](./Uploading_Traces/file_uploads.md) and via the [Push API](./Uploading_Traces/push_api.md), you can include an `annotations` field in the trace data. This field should be an array of objects, each representing an annotation. Each annotation object should have the following fields:
20+
21+
##### `content` <span class='type'>string</span> <span class='required'/>
22+
23+
The content of the annotation.
24+
25+
##### `address` <span class='type'>string</span> <span class='required'/>
26+
27+
The address of the span to annotate. This should be in the format `<path>:<start>-<end>`, where `<path>` is the path to an object in the event log, and `<start>` and `<end>` are the start and end indices of the character range to annotate.
28+
29+
##### `extra_metadata` <span class='type'>Optional[Dict[Any, Any]]</span> <span class='optional'/>
30+
31+
Additional metadata for the annotation.
32+
33+
Each metadata dictionary can have arbitrary keys and values for storing additional information about the annotation.
34+
35+
> Example Annotation
36+
```json
37+
{
38+
"content": "This is an example annotation",
39+
"address": "messages.0.content:5-10",
40+
"extra_metadata": {
41+
"source": "my-analyzer"
42+
}
43+
}
44+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
hide:
3+
- toc
4+
---
5+
6+
# GetDatasetMetadata API
7+
8+
<div class='subtitle'>Get the metadata associated with your Dataset</div>
9+
10+
The GetDatasetMetadata API allows you to get the metadata associated with a dataset in a programmatic way.
11+
12+
---
13+
### `get_dataset_metadata`
14+
15+
The `get_dataset_metadata method` is used to get the metadata for a dataset from the Invariant API using the `dataset_name`.
16+
17+
##### `request` <span class='type'>dataset_name</span> <span class='required'/>
18+
19+
The name of the dataset.
20+
21+
##### `request_kwargs` <span class='type'>Optional[Dict[str, Any]]</span> <span class='optional'/>
22+
23+
Additional keyword arguments to pass to the requests method. Default is `None`.
24+
25+
##### Return Value
26+
27+
##### <span class='type'>Dict</span>
28+
29+
The response object from the Invariant API.
30+
31+
32+
> Example
33+
```python
34+
from invariant_sdk.client import Client
35+
from invariant_sdk.types.push_traces import PushTracesRequest
36+
37+
client = Client()
38+
39+
dataset_metadata = client.get_dataset_metadata(dataset_name="some_dataset_name")
40+
```

0 commit comments

Comments
 (0)