Skip to main content

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]
  • 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 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) 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 | 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).
  • 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 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].