# Context

TokenSource context management provides a flexible framework for managing AI assistant behaviors and capabilities within the financial services ecosystem. This system implements a primary association between contexts and AI assistants, with optional linking to specific objectives or projects.

## Core Architecture

### Primary Context-Assistant Association

The system establishes a direct relationship between contexts and AI assistants, ensuring:

* Each AI assistant maintains a default context that defines its base behavior and knowledge domain
* Contexts contain specific rules, constraints, and knowledge bases tailored to financial operations
* Multiple assistants can share standardized contexts for consistent behavior across services
* Context definitions include specialized knowledge for payment processing, compliance, and security protocols

### Secondary Context-Objective Association

The system supports dynamic context assignment to objectives through:

* Flexible context switching based on project phases or requirements
* Optional linking between contexts and specific project objectives
* Support for multiple assistant personalities within a single project
* Dynamic context adaptation for different stages of financial workflows

**Base Path:** `/v1/contexts`

## Get All Contexts

**Method:** `GET`\
**Endpoint:** `https://api.tokensource.com/v1/contexts`\
**Description:** Retrieves all contexts for the authenticated user.

**Response (200 OK):**

```json
{
  "status": 200,
  "data": [
    {
      "id": 1,
      "name": "Context A",
      "instructionCommentary": "Instructions for context A",
      "apiVersion": "v1",
      "authenticationMethod": "Bearer Token",
      "responseFormat": "JSON",
      "userId": 1
    }
  ]
}
```

## Get Context by ID

**Method:** `GET`\
**Endpoint:** `https://api.tokensource.com/v1/contexts/{id}`\
**Description:** Retrieves a specific context by its ID.

**Parameters:**

* `id` (integer, required)

**Response (200 OK):**

```json
{
  "status": 200,
  "data": {
    "id": 1,
    "name": "Context A",
    "instructionCommentary": "Instructions for context A",
    "apiVersion": "v1",
    "authenticationMethod": "Bearer Token",
    "responseFormat": "JSON",
    "userId": 1,
    "components": [
      { "id": 1, "name": "Component X" },
      { "id": 2, "name": "Component Y" }
    ]
  }
}
```

**Response (404 Not Found):**

```json
{
  "status": 404,
  "message": "Context not found"
}
```

## Create Context

**Method:** `POST`\
**Endpoint:** `https://api.tokensource.com/v1/contexts`\
**Description:** Creates a new context.

**Request Body:**

```json
{
  "name": "Context B",
  "instructionCommentary": "Instructions for context B",
  "apiVersion": "v2",
  "authenticationMethod": "API Key",
  "responseFormat": "XML"
}
```

**Response (201 Created):**

```json
{
  "status": 201,
  "data": {
    "id": 2,
    "name": "Context B",
    "instructionCommentary": "Instructions for context B",
    "apiVersion": "v2",
    "authenticationMethod": "API Key",
    "responseFormat": "XML",
    "userId": 1
  }
}
```

## Update Context

**Method:** `PUT`\
**Endpoint:** `https://api.tokensource.com/v1/contexts/{id}`\
**Description:** Updates an existing context.

**Parameters:**

* `id` (integer, required)

**Request Body:**

```json
{
  "name": "Context A Updated",
  "instructionCommentary": "Updated instructions",
  "apiVersion": "v1.1",
  "authenticationMethod": "OAuth 2.0",
  "responseFormat": "JSON"
}
```

**Response (200 OK):**

```json
{
  "status": 200,
  "message": "Context updated successfully"
}
```

## Delete Context

**Method:** `DELETE`\
**Endpoint:** `https://api.tokensource.com/v1/contexts/{id}`\
**Description:** Deletes a context.

**Parameters:**

* `id` (integer, required)

**Response (200 OK):**

```json
{
  "status": 200,
  "message": "Context deleted successfully"
}
```

## Generate and Save Context

**Method:** `POST`\
**Endpoint:** `https://api.tokensource.com/v1/contexts/generate`\
**Description:** Generates and saves a new context.

**Request Body:**

```json
{
  "input": "Some input text for context generation",
  "categoryId": 1
}
```

**Response (201 Created):**

```json
{
  "status": 201,
  "message": "Context generated and saved successfully"
}
```

## Related Endpoints

### Get All Components

**Method:** `GET`\
**Endpoint:** `https://api.tokensource.com/v1/contexts/components`\
(Refer to the Components section for the response format.)

### Get All Categories

**Method:** `GET`\
**Endpoint:** `https://api.tokensource.com/v1/contexts/categories`\
(Refer to the Categories section for the response format.)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tokensource.com/context.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
