> ## Documentation Index
> Fetch the complete documentation index at: https://allhandsai-extend-api-reference-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# openhands.sdk.context

> API reference for openhands.sdk.context module

***

### class AgentContext

Bases: `BaseModel`

Central structure for managing prompt extension.

AgentContext unifies all the contextual inputs that shape how the system
extends and interprets user prompts. It combines both static environment
details and dynamic, user-activated extensions from skills.

Specifically, it provides:

* Repository context / Repo Skills: Information about the active codebase,

branches, and repo-specific instructions contributed by repo skills.

* Runtime context: Current execution environment (hosts, working
  directory, secrets, date, etc.).
* Conversation instructions: Optional task- or channel-specific rules
  that constrain or guide the agent’s behavior across the session.
* Knowledge Skills: Extensible components that can be triggered by user input
  to inject knowledge or domain-specific guidance.

Together, these elements make AgentContext the primary container responsible
for assembling, formatting, and injecting all prompt-relevant context into
LLM interactions.

#### Properties

* `current_datetime`: datetime | str | None
* `load_public_skills`: bool
* `load_user_skills`: bool
* `marketplace_path`: str | None
* `secrets`: Mapping\[str, SecretValue] | None
* `skills`: list\[[Skill](#class-skill)]
* `system_message_suffix`: str | None
* `user_message_suffix`: str | None

#### Methods

#### get\_formatted\_datetime()

Get formatted datetime string for inclusion in prompts.

* Returns:
  Formatted datetime string, or None if current\_datetime is not set.
  If current\_datetime is a datetime object, it’s formatted as ISO 8601.
  If current\_datetime is already a string, it’s returned as-is.

#### get\_secret\_infos()

Get secret information (name and description) from the secrets field.

* Returns:
  List of dictionaries with ‘name’ and ‘description’ keys.
  Returns an empty list if no secrets are configured.
  Description will be None if not available.

#### get\_system\_message\_suffix()

Get the system message with repo skill content and custom suffix.

Custom suffix can typically includes:

* Repository information (repo name, branch name, PR number, etc.)
* Runtime information (e.g., available hosts, current date)
* Conversation instructions (e.g., user preferences, task details)
* Repository-specific instructions (collected from repo skills)
* Available skills list (for AgentSkills-format and triggered skills)

- Parameters:
  * `llm_model` – Optional LLM model name for vendor-specific skill filtering.
  * `llm_model_canonical` – Optional canonical LLM model name.
  * `additional_secret_infos` – Optional list of additional secret info dicts
    (with ‘name’ and ‘description’ keys) to merge with agent\_context
    secrets. Typically passed from conversation’s secret\_registry.

Skill categorization:

* AgentSkills-format (SKILL.md): Always in `<available_skills>` (progressive

disclosure). If has triggers, content is ALSO auto-injected on trigger
in user prompts.

* Legacy with trigger=None: Full content in `<REPO_CONTEXT>` (always active)
* Legacy with triggers: Listed in `<available_skills>`, injected on trigger

#### get\_user\_message\_suffix()

Augment the user’s message with knowledge recalled from skills.

This works by:

* Extracting the text content of the user message
* Matching skill triggers against the query
* Returning formatted knowledge and triggered skill names if relevant skills were triggered

#### model\_config = (configuration object)

Configuration for the model, should be a dictionary conforming to \[ConfigDict]\[pydantic.config.ConfigDict].

***

### class BaseTrigger

Bases: `BaseModel`, `ABC`

Base class for all trigger types.

#### Methods

#### model\_config = (configuration object)

Configuration for the model, should be a dictionary conforming to \[ConfigDict]\[pydantic.config.ConfigDict].

***

### class KeywordTrigger

Bases: [`BaseTrigger`](#class-basetrigger)

Trigger for keyword-based skills.

These skills are activated when specific keywords appear in the user’s query.

#### Properties

* `keywords`: list\[str]
* `type`: Literal\['keyword']

#### Methods

#### model\_config = (configuration object)

Configuration for the model, should be a dictionary conforming to \[ConfigDict]\[pydantic.config.ConfigDict].

***

### class Skill

Bases: `BaseModel`

A skill provides specialized knowledge or functionality.

Skill behavior depends on format (is\_agentskills\_format) and trigger:

AgentSkills format (SKILL.md files):

* Always listed in `<available_skills>` with name, description, location
* Agent reads full content on demand (progressive disclosure)
* If has triggers: content is ALSO auto-injected when triggered

Legacy OpenHands format:

* With triggers: Listed in `<available_skills>`, content injected on trigger
* Without triggers (None): Full content in `<REPO_CONTEXT>`, always active

This model supports both OpenHands-specific fields and AgentSkills standard
fields ([https://agentskills.io/specification](https://agentskills.io/specification)) for cross-platform compatibility.

#### Properties

* `MAX_DESCRIPTION_LENGTH`: ClassVar\[int] = 1024
* `PATH_TO_THIRD_PARTY_SKILL_NAME`: ClassVar\[dict\[str, str]] = (configuration object)
* `allowed_tools`: list\[str] | None
* `compatibility`: str | None
* `content`: str
* `description`: str | None
* `inputs`: list\[InputMetadata]
* `is_agentskills_format`: bool
* `license`: str | None
* `mcp_tools`: dict | None
* `metadata`: dict\[str, str] | None
* `name`: str
* `resources`: SkillResources | None
* `source`: str | None
* `trigger`: Annotated\[[KeywordTrigger](#class-keywordtrigger) | [TaskTrigger](#class-tasktrigger), FieldInfo(annotation=NoneType, required=True, discriminator='type')] | None

#### Methods

#### extract\_variables()

Extract variables from the content.

Variables are in the format (variable).

#### get\_skill\_type()

Determine the type of this skill.

* Returns:
  “agentskills” for AgentSkills format, “repo” for always-active skills,
  “knowledge” for trigger-based skills.

#### get\_triggers()

Extract trigger keywords from this skill.

* Returns:
  List of trigger strings, or empty list if no triggers.

#### classmethod load()

Load a skill from a markdown file with frontmatter.

The agent’s name is derived from its path relative to skill\_base\_dir,
or from the directory name for AgentSkills-style SKILL.md files.

Supports both OpenHands-specific frontmatter fields and AgentSkills
standard fields ([https://agentskills.io/specification](https://agentskills.io/specification)).

* Parameters:
  * `path` – Path to the skill file.
  * `skill_base_dir` – Base directory for skills (used to derive relative names).
  * `strict` – If True, enforce strict AgentSkills name validation.
    If False, allow relaxed naming (e.g., for plugin compatibility).

#### match\_trigger()

Match a trigger in the message.

Returns the first trigger that matches the message, or None if no match.
Only applies to KeywordTrigger and TaskTrigger types.

#### model\_config = (configuration object)

Configuration for the model, should be a dictionary conforming to \[ConfigDict]\[pydantic.config.ConfigDict].

#### model\_post\_init()

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

* Parameters:
  * `self` – The BaseModel instance.
  * `context` – The context.

#### requires\_user\_input()

Check if this skill requires user input.

Returns True if the content contains variables in the format (variable).

#### to\_skill\_info()

Convert this skill to a SkillInfo.

* Returns:
  SkillInfo containing the skill’s essential information.

***

### class SkillKnowledge

Bases: `BaseModel`

Represents knowledge from a triggered skill.

#### Properties

* `content`: str
* `location`: str | None
* `name`: str
* `trigger`: str

#### Methods

#### model\_config = (configuration object)

Configuration for the model, should be a dictionary conforming to \[ConfigDict]\[pydantic.config.ConfigDict].

#### **init**()

***

### class TaskTrigger

Bases: [`BaseTrigger`](#class-basetrigger)

Trigger for task-specific skills.

These skills are activated for specific task types and can modify prompts.

#### Properties

* `triggers`: list\[str]
* `type`: Literal\['task']

#### Methods

#### model\_config = (configuration object)

Configuration for the model, should be a dictionary conforming to \[ConfigDict]\[pydantic.config.ConfigDict].


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