# Runtime

## Key Methods:

* **`initialize()`**: Sets up the agent's runtime environment, including services, plugins, and knowledge processing.
* **`processActions()`**: Executes actions based on message content and state.
* **`evaluate()`**: Assesses messages and state using registered evaluators.
* **`composeState()`**: Constructs the agent's state object for response generation.
* **`updateRecentMessageState()`**: Updates the state with recent messages and attachments.
* **`registerService()`**: Adds a service to the runtime.
* **`registerMemoryManager()`**: Registers a memory manager for specific types of memories.
* **`ensureRoomExists()` / `ensureUserExists()`**: Ensures the existence of rooms and users in the database.

## State Management:

```typescript
interface State {
    // Core identifiers
    userId?: UUID;
    agentId?: UUID;
    roomId: UUID;

    // Character information
    bio: string;
    lore: string;
    messageDirections: string;
    postDirections: string;

    // Conversation context
    actors: string;
    actorsData?: Actor[];
    recentMessages: string;
    recentMessagesData: Memory[];

    // Goals and knowledge
    goals?: string;
    goalsData?: Goal[];
    knowledge?: string;
    knowledgeData?: KnowledgeItem[];
    ragKnowledgeData?: RAGKnowledgeItem[];
}

// State management methods
async function manageState() {
    // Initial state composition
    const state = await runtime.composeState(message, {
        additionalContext: "custom context"
    });

    // Update state with new messages
    const updatedState = await runtime.updateRecentMessageState(state);
}
```


---

# 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.tars.pro/sona-framework/core-concepts/runtime.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.
