> For the complete documentation index, see [llms.txt](https://methara.gitbook.io/methara-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://methara.gitbook.io/methara-docs/methara-developer-documentation/patterns.md).

# Patterns

The Patterns module builds a behavioral profile from conversation history.

This helps your agent personalize tone and responses over time without external storage.

### Patterns.profile(conversation)

This is the all-in-one function. It runs all four analyses in one call.

It also mutates `conversation.context.userPatterns` as a convenience side effect.

```ts
import { Patterns, type Conversation } from 'methara';

const conversation: Conversation = {
  history: [
    { role: 'user', content: 'Hey, can you quickly check my schedule?' },
    { role: 'assistant', content: 'Of course! Here are your tasks...' },
    { role: 'user', content: 'ASAP please, I have a deadline!' },
  ],
  context: {},
};

const profile = Patterns.profile(conversation);
// {
//   urgency: 'high',
//   style: { formal: 0, casual: 1, detailed: 0, concise: 1 },
//   time: { prefersMorning: false, ... },
//   taskPrefs: { prefersTeamTasks: false, prefersReminders: false, ... }
// }
// Also available on:
// conversation.context.userPatterns
```

### Individual methods

| Method                           | Input        | Returns                                                                                  |
| -------------------------------- | ------------ | ---------------------------------------------------------------------------------------- |
| `Patterns.urgency(messages)`     | `string[]`   | `'high' \| 'medium' \| 'low'`                                                            |
| `Patterns.style(messages)`       | `string[]`   | `{ formal, casual, detailed, concise }`                                                  |
| `Patterns.time(messages)`        | `string[]`   | `{ prefersMorning, prefersAfternoon, prefersEvening, prefersWeekdays, prefersWeekends }` |
| `Patterns.taskPrefs(messages)`   | `string[]`   | `{ prefersTeamTasks, prefersDetailedTasks, prefersQuickTasks, prefersReminders }`        |
| `Patterns.profile(conversation)` | Conversation | UserProfile                                                                              |

```ts
Patterns.urgency(['I need this ASAP, it\'s urgent!']); // 'high'
Patterns.urgency(['Whenever you get a chance, no rush']); // 'low'
Patterns.style(['Hey! Can you quickly do this? Thanks!']);
// { formal: 0, casual: 2, detailed: 0, concise: 1 }
```

{% hint style="info" %}
The urgency detector also accounts for ALL CAPS usage and exclamation marks.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://methara.gitbook.io/methara-docs/methara-developer-documentation/patterns.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.
