Types and Protocols
Core data types and plugin protocols.
Message, PartialMessage, Session, and ToolDescriptor are frozen
dataclasses. Their nested lists and dictionaries remain ordinary mutable
Python containers, so callers must treat returned values as immutable by
convention and use AgentCore operations to create updated sessions.
Plugin protocols define structural interfaces. Provider, provider-extension, and feature hooks collaborate through explicit shared provider state during a request; tools keep separate state. Hooks may perform I/O where their individual contracts permit it.
Examples:
Creating immutable messages and sessions:
from agent_core.types import Message, Session
msg = Message(role="user", content="Hello")
session = Session(session_id="s1", messages=[msg])
data = session.to_dict()
restored = Session.from_dict(data)
MessageRole
module-attribute
MessageRole = Literal['system', 'user', 'assistant', 'tool']
Conversation roles accepted by Core message operations.
BasePlugin
Bases: Protocol
Common identity, configuration, and UI protocol for plugin classes.
Provider, provider-extension, feature, and tool protocols inherit these common hooks. Plugin instances are short-lived per request; durable data belongs in explicit plugin state or application-managed storage rather than instance attributes.
get_config_schema
get_config_schema()
Return JSON schema describing this plugin's configuration.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
JSON schema dictionary. |
Source code in agent_core/types.py
97 98 99 100 101 102 103 | |
get_ui_elements
get_ui_elements(config, context=None)
Return UI element definitions contributed by this plugin.
The returned list describes configuration and display-oriented
elements that applications can use to build UIs. Each element is a
plain dictionary; the core treats these dictionaries as opaque and
flattens them via :meth:AgentCore.get_ui_schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict[str, Any]
|
Effective configuration for the current agent/request. |
required |
context
|
Optional[Dict[str, Any]]
|
Optional derived context for schema generation. The core
provides keys such as |
None
|
Note
The canonical hook shape is (config, context=None). For backward
compatibility, adapters also accept legacy plugin
implementations that define get_ui_elements(self),
get_ui_elements(self, config), get_ui_elements(self, config, tags, models),
or get_ui_elements(self, config, tags, models, context).
Recommended element shapes:
- Configuration elements (default
ui_type == "config"):
Used to describe editable settings for the plugin. Typical keys are::
{
"type": "checkbox" | "text" | "number" | "select" | "dropdown" | ...,
"key": "config_key", # stable configuration key
"label": "Human label", # short caption for UIs
"description": "Longer help text", # optional
"disabled": False, # optional non-editable state
"options": [ # for select-like fields
"value" | {"value": "v", "label": "Display"},
],
"placeholder": "Search or enter a value",
"custom_value": { # optional dropdown escape hatch
"enabled": True,
"pattern": r"^[^\s]+$",
"option_label": "Use '{value}'",
},
"rich_ui": { # optional self-contained compact UI
"kind": "dropdown",
"label": "Short label",
"show_label": False,
"options": [],
"placements": ["composer"],
},
... # plugin-specific extras are allowed
}
When "ui_type" is missing or falsy, the core normalizes the
element to "config" and will de-duplicate on "key" when
flattening the global UI schema. A disabled element remains visible;
applications should prevent edits and render "description" as
the reason or explanatory note.
- Message footer elements (
ui_type == "message_footer"):
Used by some applications (for example, the terminal client) to render a compact footer line under individual messages. A common shape is::
{
"ui_type": "message_footer",
"data": "metadata.timestamp", # dotted JSON path
"template": "{{data}}", # optional; defaults vary
...
}
"data" is interpreted as a dotted path into the core message
dictionary (e.g. "metadata.timestamp"). "template" is a
simple string where "{{data}}" is replaced with the resolved
value, but individual applications are free to use different
conventions.
- Status bar elements (
ui_type == "status_bar"):
Similar to "message_footer" but intended for persistent status
bars (for example, values derived from the last assistant message)::
{
"ui_type": "status_bar",
"data": "metadata.total_cost",
"template": "Total: {{data}}",
...
}
The core will attach a "plugin" field (when absent) naming the
contributing plugin class when it flattens UI elements. Plugins may
include additional keys beyond those shown above; callers should treat
the returned element dictionaries as immutable.
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List of UI element dictionaries. |
Source code in agent_core/types.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
FeaturePlugin
Bases: BasePlugin, Protocol
Protocol for feature plugins (cold path; shared provider state).
Features operate on the cold path only (no per-chunk processing). They can transform both provider-native messages and core messages during finalize and may update the shared provider state during init and initialize_request.
Attributes:
| Name | Type | Description |
|---|---|---|
priority |
Optional execution priority (default: 100). Lower numbers run first. Features are sorted by priority within the feature execution chain. |
Example
Minimal feature that annotates finals:
class TagFeature:
name = "tag"
version = "1.0.0"
priority = 100 # Optional: default priority
def get_config_schema(self):
return {"enabled": {"type": "boolean", "default": True}}
def init(self, config, state):
return state
def to_native_messages(self, messages, native_messages):
return native_messages
def from_native_messages(self, native_messages, messages):
return messages
def initialize_request(self, native_messages, state):
return native_messages, state
def finalize(self, final_messages, native_messages, state):
finals = [{**m, "metadata": {**m.get("metadata", {}), "tag": True}} for m in final_messages]
return finals, native_messages, state
apply_completion
apply_completion(config, text, completion)
Optionally transform an accepted completion into a final snippet.
Applications may call this hook when a user accepts one of the
completion entries previously returned by :meth:get_completions.
The default implementation returns an empty string, indicating that
the feature does not wish to modify the completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict[str, Any]
|
Application-supplied configuration for the current agent or request. |
required |
text
|
str
|
Full buffer text after the completion has been applied
(for example, input containing |
required |
completion
|
Dict[str, Any]
|
The completion descriptor dict that was accepted,
as previously returned by :meth: |
required |
Returns:
| Type | Description |
|---|---|
str
|
A replacement string to insert into the buffer in place of the |
str
|
completion text, or an empty string/falsey value to indicate no |
str
|
special handling. |
Source code in agent_core/types.py
1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 | |
execute_action
execute_action(action_id, session, native_messages, params, context, state)
Execute a session-scoped feature action.
The supported return contract matches provider-extension actions:
features may return replacement native_messages and/or a
session_metadata mapping that is merged into the session.
For the core-owned response_finalize lifecycle, features may also
return final_messages to replace the current turn's final core
messages before they are emitted or appended to the session.
The context parameter provides layered access to runtime capabilities:
Layer 1 (Core - always present):
- core: AgentCore instance for session/message operations
- config: Current resolved request configuration
- trigger_source: Where the action was triggered ("core", "application")
- session: Serialized session dict (session.to_dict())
- lifecycle: Lifecycle trigger name (for lifecycle-triggered actions)
- final_messages: Current turn final core messages for
response_finalize
- native_final_messages: Provider-native finals for the current
turn for response_finalize
- native_messages: Full provider-native history for
response_finalize
- stream: Whether the request is streaming for
response_finalize
- turn_native_start_index: Native-history starting offset for
the current turn for response_finalize
Layer 2 (Application - when called from AgentApplication):
- app and application: AgentApplication instance
- base_config: Full base configuration (all agents)
- session_asset_store: Session asset store for file attachments
- runtime_state_root: Persistent runtime-state root directory
Layer 3 (Terminal/Server - implementation-specific): - Implementation-specific keys added by terminal or HTTP server
Caller-supplied context is additive only. Reserved keys owned by the context builders are not overridden; on clashes the builder keeps the owned value and emits a warning.
Features can check for enhanced capabilities using context.get("app").
Source code in agent_core/types.py
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 | |
finalize
finalize(final_messages, native_messages, state, *, context=None)
Final cold-path processing after provider and extensions complete.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
final_messages
|
List[Dict[str, Any]]
|
Provider-native final messages emitted this turn (deltas). |
required |
native_messages
|
List[Dict[str, Any]]
|
Full provider-native message history for this turn. |
required |
state
|
Dict[str, Any]
|
Current shared provider state. |
required |
context
|
Optional[Dict[str, Any]]
|
Optional request context for this turn. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[List[Dict[str, Any]], List[Dict[str, Any]], Dict[str, Any]]
|
Tuple of (final_messages, native_messages, new_state), all provider-native. |
Source code in agent_core/types.py
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 | |
finalize_tool_call
finalize_tool_call(tool_message, state, *, context=None)
Act on the final tool message after a tool call execution.
Runs once per tool call after execution, before the final core
tool message is yielded to the caller (and therefore before
the application tool loop appends it or emits tool events). Also
runs for synthesized results (failed inspection, no handler,
stream error); the context carries a tool_error fact in those
cases. Extensions run before features; priority order within
each kind.
Plugins own any measurement computed here (e.g. duration from the context-carried timestamp facts) and stamp it onto the returned message; the framework never computes or stamps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_message
|
Dict[str, Any]
|
Final core |
required |
state
|
Dict[str, Any]
|
Current shared provider state. |
required |
context
|
Optional[Dict[str, Any]]
|
Tool-call context with framework facts (the prepare
facts plus |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Tuple of (tool_message, new_state). Return the input message |
Dict[str, Any]
|
unchanged when the plugin stamps nothing. |
Source code in agent_core/types.py
1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 | |
forbidden_tags
forbidden_tags()
Tags that must NOT be present for this feature to be enabled.
If any of these tags are in the available tag set, the feature is disabled. This provides a negative constraint complementary to required_tags.
Source code in agent_core/types.py
1093 1094 1095 1096 1097 1098 1099 | |
from_native_messages
from_native_messages(native_messages, messages, state=None, *, context=None)
Transform provider-native messages back into core messages.
Note
In the default AgentCore request flow, feature transforms run
after the provider and provider extension from_native_messages
transforms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
native_messages
|
List[Dict[str, Any]]
|
Provider-native messages to transform. |
required |
messages
|
List[Dict[str, Any]]
|
Core session messages for context. |
required |
state
|
Dict[str, Any] | None
|
Optional shared provider state (available when called via ProviderWrapper). |
None
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
Updated core messages. |
Source code in agent_core/types.py
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 | |
get_actions
get_actions(state)
Return session-scoped action definitions for this feature.
Feature actions follow the same session-scoped shape as provider extension actions. They are optional and are primarily used for lifecycle-triggered single-session mutations.
Source code in agent_core/types.py
1362 1363 1364 1365 1366 1367 1368 1369 | |
get_completions
get_completions(config, text)
Return completion suggestions for the given input text.
Each completion entry is a dictionary whose structure is application-defined. A common shape is::
{
"replacement": "text to insert",
"start": 5, # 0-based index in input text
"display": "label shown in UI",
"display_meta": "extra description",
}
Implementations may ignore text when not relevant and should
return an empty list when no completions apply.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict[str, Any]
|
Application-supplied configuration for the current agent or request. |
required |
text
|
str
|
Full text before the cursor (for example, the contents of an input line in a terminal UI). |
required |
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List of completion descriptor dictionaries. |
Source code in agent_core/types.py
1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 | |
get_models
get_models(config, models)
Statelessly transform or provide model descriptors.
Note
In the default AgentCore request flow, model discovery starts
with the provider's get_models hook, then passes through provider
extensions, and finally through feature get_models hooks.
Source code in agent_core/types.py
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 | |
get_tags
get_tags(config, models)
Return capability/environment tags contributed by this feature.
Note
In the default AgentCore dependency-resolution flow, these tags
are aggregated with tags from the provider, provider extensions, and
tools to decide which plugins are enabled.
Source code in agent_core/types.py
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 | |
get_template
get_template(config)
Return a template string used by this feature.
This hook is intended for applications that need a feature-specific textual template (for example, to construct editor snippets or autocomplete expansions). Implementations may return an empty string when no template is applicable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict[str, Any]
|
Application-supplied configuration for the current agent or request. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Template string, or an empty string if the feature does not |
str
|
expose a template. |
Source code in agent_core/types.py
1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 | |
init
init(config, state)
Initialize with application config and shared provider state.
Note
In the default AgentCore request flow, feature init hooks run
after the provider (and any active provider extensions) have
initialized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict[str, Any]
|
Application-supplied configuration. |
required |
state
|
Dict[str, Any]
|
Current shared provider state. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Updated shared provider state (or the same state). |
Source code in agent_core/types.py
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 | |
initialize_request
initialize_request(native_messages, state, *, context=None)
Prepare for a new request with provider-native messages.
Note
In the default AgentCore request flow, feature hooks run after
the provider (and any provider extensions) have run their
initialize_request hooks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
native_messages
|
List[Dict[str, Any]]
|
Provider-native messages for this request. |
required |
state
|
Dict[str, Any]
|
Current shared provider state. |
required |
context
|
Optional[Dict[str, Any]]
|
Optional request context. The core provides keys such as
|
None
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
Tuple of (provider-native messages for this request, updated shared state). |
Dict[str, Any]
|
Implementations MAY return the same native_messages when only state changes. |
Source code in agent_core/types.py
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 | |
is_enabled
is_enabled(config, tags, models, context)
Return whether this feature should be enabled given the current context.
This method allows features to implement complex enablement logic that goes beyond simple tag matching. It receives the full runtime context including configuration, computed tags, model descriptors, and information about other enabled plugins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict[str, Any]
|
Effective configuration for the current request. |
required |
tags
|
List[str]
|
Capability tags computed for this config. |
required |
models
|
List[Dict[str, Any]]
|
Model descriptors computed for this config. |
required |
context
|
Dict[str, Any]
|
Additional context including: - "enabled_plugin_ids": dict mapping plugin kind to list of enabled plugin ids - "disabled_plugins": config-level disabled plugin id list - "force_enabled_plugins": config-level force-enabled plugin id list |
required |
Returns:
| Name | Type | Description |
|---|---|---|
True |
Optional[bool]
|
feature is enabled (bypass required_tags/forbidden_tags check) |
False |
Optional[bool]
|
feature is disabled |
None |
Optional[bool]
|
fall back to required_tags/forbidden_tags check (default) |
Source code in agent_core/types.py
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 | |
prepare_appended_message
prepare_appended_message(message, state=None, *, context=None)
Transform a message immediately before it is appended to a session.
Runs inside :meth:AgentCore.add_message for end-of-session
appends, before the message is converted to provider-native form,
so metadata stamped here persists into native _metadata.
Assistant finals do not pass through this hook (they enter via
the request pipeline, where finalize runs); after_index
inserts do not trigger it.
Extensions run before features; priority order within each kind. State is threaded through the chain so chained plugins can read each other's state. For appended tool results, the context carries the tool-call execution facts in addition to the append facts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
Dict[str, Any]
|
Core message dict ( |
required |
state
|
Optional[Dict[str, Any]]
|
Shared provider state when available. |
None
|
context
|
Optional[Dict[str, Any]]
|
Append context with |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Tuple of (message, new_state). Return the input message |
Dict[str, Any]
|
unchanged when the plugin stamps nothing. |
Source code in agent_core/types.py
1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 | |
prepare_tool_call
prepare_tool_call(tool_call, state, *, context=None)
Observe or transform a tool call before execution; update state.
Runs once per inspectable tool call, immediately before the owning
tool plugin executes it. Extensions run before features (mirroring
the request pipeline); within each kind, plugins run in priority
order (lower first). The framework re-inspects the returned call
before resolving the handler, so sanitizing and interception are
supported; a transformed call that no longer inspects follows the
existing synthesized-error path. Transformers own correlation: the
tool-result message's tool_call_id reflects the transformed call.
The context carries framework-owned facts only: tool_call_id,
tool_name, tool_plugin, started_at (ISO 8601 UTC) and
started_at_mono captured immediately before execution, plus the
caller's context (session_id, request_id). The framework
never computes durations or stamps messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_call
|
Dict[str, Any]
|
The inspected tool call about to execute. |
required |
state
|
Dict[str, Any]
|
Current shared provider state. |
required |
context
|
Optional[Dict[str, Any]]
|
Tool-call context with framework facts. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Tuple of (tool_call, new_state). Return the input tool_call |
Dict[str, Any]
|
unchanged unless the plugin intentionally transforms the call. |
Source code in agent_core/types.py
1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 | |
prepare_tools
prepare_tools(config, tools, context=None)
Filter or transform the available tool catalog for a request.
This hook runs before provider/extensions/features init hooks for
the request so that the effective tool list can be threaded through the
compatibility shim at config["tools"].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict[str, Any]
|
Effective configuration for this request, including any UI-driven tool gating selections. |
required |
tools
|
List[ToolDescriptor]
|
Normalized tool catalog for this request before policy filtering. |
required |
context
|
Optional[Dict[str, Any]]
|
Request-preparation context. The core provides keys such
as |
None
|
Returns:
| Type | Description |
|---|---|
List[ToolDescriptor]
|
The effective tool descriptor list for this request. |
Source code in agent_core/types.py
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 | |
required_tags
required_tags()
Tags that must be present for this feature to be enabled.
Source code in agent_core/types.py
1089 1090 1091 | |
to_native_messages
to_native_messages(messages, native_messages, state=None, *, context=None)
Transform provider-native messages using visibility of core messages.
Note
When the core converts a single new message (e.g., via add_message), it passes a list containing only that single message in "messages". Implementations must handle both full-history lists and single-message lists.
In the default AgentCore request flow, feature transforms run
after the provider and provider extension to_native_messages
transforms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
List[Dict[str, Any]]
|
Core session messages for context (may be a single-element list for add_message). |
required |
native_messages
|
List[Dict[str, Any]]
|
Current provider-native messages. |
required |
state
|
Dict[str, Any] | None
|
Optional shared provider state (available when called via ProviderWrapper). |
None
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
Updated provider-native messages. |
Source code in agent_core/types.py
1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 | |
Message
dataclass
Message(role, content, metadata=None, multipart_content=None, tool_result=None)
Frozen value representing one completed core conversation message.
The dataclass prevents field reassignment. Nested metadata, multipart content, and tool-result dictionaries/lists are mutable Python objects and must be treated as immutable by convention.
Attributes:
| Name | Type | Description |
|---|---|---|
role |
MessageRole
|
Message role ("system", "user", "assistant", or "tool"). |
content |
Any
|
Provider-independent content value. It is commonly text but may be another JSON-compatible value. |
metadata |
Optional[Dict[str, Any]]
|
Optional auxiliary data such as tool calls, tool-call IDs, citations, reasoning, or application metadata. |
multipart_content |
Optional[List[Dict[str, Any]]]
|
Optional structured content parts. Dictionary
serialization uses the key |
tool_result |
Optional[Dict[str, Any]]
|
Optional canonical structured result for a tool message.
Dictionary serialization uses the key |
Examples:
>>> msg = Message(role="user", content="Hello!")
>>> msg.role
'user'
>>> msg.content
'Hello!'
from_dict
classmethod
from_dict(data)
Create a message from its external dictionary representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dict[str, Any]
|
Dictionary containing |
required |
Returns:
| Type | Description |
|---|---|
Message
|
New Message instance. |
Source code in agent_core/types.py
1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 | |
to_dict
to_dict()
Return the external dictionary representation.
Metadata, multipart content, and tool-result containers are deep copied when present. Optional values are omitted when falsey.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with |
Dict[str, Any]
|
|
Source code in agent_core/types.py
1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 | |
PartialMessage
dataclass
PartialMessage(role, content, metadata=None)
Frozen incremental message emitted during streaming.
Each instance represents new output for one stream step rather than the complete content accumulated so far.
Attributes:
| Name | Type | Description |
|---|---|---|
role |
MessageRole
|
Core role associated with the partial output. |
content |
Any
|
Incremental content value. |
metadata |
Optional[Dict[str, Any]]
|
Optional incremental metadata such as reasoning content. |
Nested metadata is treated as immutable by convention.
ProviderExtensionPlugin
Bases: BasePlugin, Protocol
Protocol for provider extension plugins (shared provider state, hot + cold path observers).
Provider extensions run in the provider's language and observe/transform streaming chunks on the hot path and participate in finalize on the cold path. They do not own separate state; they receive and update the shared provider state.
Attributes:
| Name | Type | Description |
|---|---|---|
priority |
Optional execution priority (default: 100). Lower numbers run first. Extensions are sorted by priority within the extension execution chain. |
Example
Basic prefix extension:
from typing import Any, Dict, List, Tuple, Optional
class PrefixExt:
name = "prefix"
version = "1.0.0"
priority = 50 # Optional: run before extensions with default priority (100)
def get_config_schema(self):
return {"prefix": {"type": "string", "default": "[EXT]"}}
def init(self, config, state):
return state
def process_chunk(self, native_chunk, partial_messages, final_messages, native_messages, state):
pfx = state.get("config", {}).get("prefix", "[EXT]")
finals = [{**m, "content": f"{pfx} {m['content']}"} for m in final_messages]
return partial_messages, finals, native_messages, state
def finalize(self, final_messages, native_messages, state):
return final_messages, native_messages, state
accepted_tool_schema_formats
accepted_tool_schema_formats(config, state=None)
Return additional tool schema formats this extension can inject.
Source code in agent_core/types.py
781 782 783 784 785 786 787 | |
emitted_tool_call_formats
emitted_tool_call_formats(config, state=None)
Return additional tool-call formats this extension can surface.
Source code in agent_core/types.py
789 790 791 792 793 794 795 | |
execute_action
execute_action(action_id, session, native_messages, params, context, state)
Execute a session-scoped provider-native action.
The returned mapping is generic. Extensions should always return a
full native_messages list representing the new provider-native
history for the session. Optional control keys currently understood by
the core include:
session_metadata: mapping merged intosession.metadata
For the core-owned response_finalize lifecycle, actions may also
return final_messages to replace the current turn's in-flight final
core messages before they are emitted or appended to the session.
Additional keys are preserved and surfaced back to higher layers as an opaque result payload.
The context parameter provides layered access to runtime capabilities
(see FeaturePlugin.execute_action for details on context structure).
Source code in agent_core/types.py
978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 | |
finalize
finalize(final_messages, native_messages, state, *, context=None)
Final cold-path processing after provider streaming/finalize.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
final_messages
|
List[Dict[str, Any]]
|
Provider-native final messages emitted this turn (deltas). |
required |
native_messages
|
List[Dict[str, Any]]
|
Full provider-native message history for this turn. |
required |
state
|
Dict[str, Any]
|
Current shared provider state. |
required |
context
|
Optional[Dict[str, Any]]
|
Optional request context for this turn. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[List[Dict[str, Any]], List[Dict[str, Any]], Dict[str, Any]]
|
Tuple of (final_messages, native_messages, new_state), all provider-native. |
Source code in agent_core/types.py
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 | |
finalize_tool_call
finalize_tool_call(tool_message, state, *, context=None)
Act on the final tool message after a tool call execution.
Runs once per tool call after execution, before the final core
tool message is yielded to the caller (and therefore before
the application tool loop appends it or emits tool events). Also
runs for synthesized results (failed inspection, no handler,
stream error); the context carries a tool_error fact in those
cases. Extensions run before features; priority order within
each kind.
Plugins own any measurement computed here (e.g. duration from the context-carried timestamp facts) and stamp it onto the returned message; the framework never computes or stamps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_message
|
Dict[str, Any]
|
Final core |
required |
state
|
Dict[str, Any]
|
Current shared provider state. |
required |
context
|
Optional[Dict[str, Any]]
|
Tool-call context with framework facts (the prepare
facts plus |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Tuple of (tool_message, new_state). Return the input message |
Dict[str, Any]
|
unchanged when the plugin stamps nothing. |
Source code in agent_core/types.py
884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 | |
forbidden_tags
forbidden_tags()
Tags that must NOT be present for this extension to be enabled.
If any of these tags are in the available tag set, the extension is disabled. This provides a negative constraint complementary to required_tags.
Source code in agent_core/types.py
650 651 652 653 654 655 656 | |
from_native_messages
from_native_messages(native_messages, messages, state=None, *, context=None)
Transform provider-native messages back into core messages.
Note
In the default AgentCore request flow, extension transforms run
after the provider's from_native_messages conversion and before
feature transforms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
native_messages
|
List[Dict[str, Any]]
|
Provider-native messages to transform. |
required |
messages
|
List[Dict[str, Any]]
|
Core session messages for context. |
required |
state
|
Dict[str, Any] | None
|
Optional shared provider state (available when called via ProviderWrapper). |
None
|
context
|
Optional[Dict[str, Any]]
|
Optional request/runtime context for this conversion. |
None
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
Updated core messages. |
Source code in agent_core/types.py
718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 | |
get_actions
get_actions(state)
Return session-scoped action definitions for this extension.
These actions are analogous to application-plugin actions, but they
operate only on a single session's provider-native history. The core
owns session loading/saving and passes the selected session, current
provider-native history, validated action params, and shared provider
state into :meth:execute_action.
Action definitions are plain dictionaries. A common shape is::
{
"id": "compact_native_history",
"label": "Compact native history",
"description": "Provider-native session action.",
"inputs": {
"instructions": {"type": "string", "required": False},
},
}
Transport-specific inputs such as session_id are handled by higher
layers and should not be declared here unless the extension itself
needs them.
Source code in agent_core/types.py
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 | |
get_models
get_models(config, models)
Statelessly transform or provide model descriptors.
Implementations must not mutate the incoming models list; they should instead return a new list.
Note
In the default AgentCore request flow, model discovery starts
with the provider's get_models hook and then passes through each
extension's get_models hook.
Source code in agent_core/types.py
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 | |
get_tags
get_tags(config, models)
Return capability/environment tags contributed by this extension.
Note
In the default AgentCore dependency-resolution flow, these tags
are aggregated with tags from the provider, other extensions,
features, and tools to decide which plugins are enabled.
Source code in agent_core/types.py
632 633 634 635 636 637 638 639 640 641 642 643 644 | |
get_tool_interop_contribution
get_tool_interop_contribution(config, state=None)
Return extension-contributed tool interop accessors/adapters.
Source code in agent_core/types.py
771 772 773 774 775 776 777 778 779 | |
init
init(config, state)
Initialize with application config and shared provider state.
Note
In the default AgentCore request flow, provider extensions are
initialized after the provider's init hook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict[str, Any]
|
Application-supplied configuration. |
required |
state
|
Dict[str, Any]
|
Current shared provider state. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Updated shared provider state (or the same state). |
Source code in agent_core/types.py
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 | |
initialize_request
initialize_request(native_messages, state, *, context=None)
Prepare for a new request with provider-native messages.
Note
In the default AgentCore request flow, this hook runs after the
provider's initialize_request hook and before any feature
initialize_request hooks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
native_messages
|
List[Dict[str, Any]]
|
Provider-native messages for this request. |
required |
state
|
Dict[str, Any]
|
Current shared provider state. |
required |
context
|
Optional[Dict[str, Any]]
|
Optional request context. The core provides keys such as
|
None
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
Tuple of (provider-native messages for this request, updated shared state). |
Dict[str, Any]
|
Implementations MAY return the same native_messages when only state changes. |
Source code in agent_core/types.py
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 | |
is_enabled
is_enabled(config, tags, models, context)
Return whether this extension should be enabled given the current context.
This method allows extensions to implement complex enablement logic that goes beyond simple tag matching. It receives the full runtime context including configuration, computed tags, model descriptors, and information about other enabled plugins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict[str, Any]
|
Effective configuration for the current request. |
required |
tags
|
List[str]
|
Capability tags computed for this config. |
required |
models
|
List[Dict[str, Any]]
|
Model descriptors computed for this config. |
required |
context
|
Dict[str, Any]
|
Additional context including: - "enabled_plugin_ids": dict mapping plugin kind to list of enabled plugin ids - "disabled_plugins": config-level disabled plugin id list - "force_enabled_plugins": config-level force-enabled plugin id list |
required |
Returns:
| Name | Type | Description |
|---|---|---|
True |
Optional[bool]
|
extension is enabled (bypass required_tags/forbidden_tags check) |
False |
Optional[bool]
|
extension is disabled |
None |
Optional[bool]
|
fall back to required_tags/forbidden_tags check (default) |
Source code in agent_core/types.py
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 | |
prepare_appended_message
prepare_appended_message(message, state=None, *, context=None)
Transform a message immediately before it is appended to a session.
Runs inside :meth:AgentCore.add_message for end-of-session
appends, before the message is converted to provider-native form,
so metadata stamped here persists into native _metadata.
Assistant finals do not pass through this hook (they enter via
the request pipeline, where finalize runs); after_index
inserts do not trigger it.
Extensions run before features; priority order within each kind. State is threaded through the chain so chained plugins can read each other's state. For appended tool results, the context carries the tool-call execution facts in addition to the append facts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
Dict[str, Any]
|
Core message dict ( |
required |
state
|
Optional[Dict[str, Any]]
|
Shared provider state when available. |
None
|
context
|
Optional[Dict[str, Any]]
|
Append context with |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Tuple of (message, new_state). Return the input message |
Dict[str, Any]
|
unchanged when the plugin stamps nothing. |
Source code in agent_core/types.py
917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 | |
prepare_tool_call
prepare_tool_call(tool_call, state, *, context=None)
Observe or transform a tool call before execution; update state.
Runs once per inspectable tool call, immediately before the owning
tool plugin executes it. Extensions run before features (mirroring
the request pipeline); within each kind, plugins run in priority
order (lower first). The framework re-inspects the returned call
before resolving the handler, so sanitizing and interception are
supported; a transformed call that no longer inspects follows the
existing synthesized-error path. Transformers own correlation: the
tool-result message's tool_call_id reflects the transformed call.
The context carries framework-owned facts only: tool_call_id,
tool_name, tool_plugin, started_at (ISO 8601 UTC) and
started_at_mono captured immediately before execution, plus the
caller's context (session_id, request_id). The framework
never computes durations or stamps messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_call
|
Dict[str, Any]
|
The inspected tool call about to execute. |
required |
state
|
Dict[str, Any]
|
Current shared provider state. |
required |
context
|
Optional[Dict[str, Any]]
|
Tool-call context with framework facts. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Tuple of (tool_call, new_state). Return the input tool_call |
Dict[str, Any]
|
unchanged unless the plugin intentionally transforms the call. |
Source code in agent_core/types.py
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 | |
process_chunk
process_chunk(native_chunk, partial_messages, final_messages, native_messages, state)
Observe/modify provider outputs for a streaming chunk.
Called on the hot path for each provider-native chunk. May be called with native_chunk=None during provider finalize.
Note
In the default AgentCore request flow, extensions run after the
provider's process_chunk hook. Multiple extensions are invoked
in order; features are not invoked on the hot path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
native_chunk
|
Optional[Dict[str, Any]]
|
Provider-native streaming chunk, or None during finalize. |
required |
partial_messages
|
List[Dict[str, Any]]
|
Current list of partial provider-native messages. |
required |
final_messages
|
List[Dict[str, Any]]
|
Current list of final provider-native messages. |
required |
native_messages
|
List[Dict[str, Any]]
|
Current full provider-native message history. |
required |
state
|
Dict[str, Any]
|
Current shared provider state. |
required |
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
Tuple of (updated_partial_messages, updated_final_messages, updated_native_messages, new_state). |
List[Dict[str, Any]]
|
updated_native_messages MUST be full history (not a delta). |
Source code in agent_core/types.py
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
required_tags
required_tags()
Tags that must be present for this extension to be enabled.
Source code in agent_core/types.py
646 647 648 | |
to_native_messages
to_native_messages(messages, native_messages, state=None, *, context=None)
Transform provider-native messages using visibility of core messages.
Note
When the core converts a single new message (e.g., via add_message), it passes a list containing only that single message in "messages". Implementations must handle both full-history lists and single-message lists.
In the default AgentCore request flow, extension transforms run
after the provider's to_native_messages conversion and before
feature transforms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
List[Dict[str, Any]]
|
Core session messages for context (may be a single-element list for add_message). |
required |
native_messages
|
List[Dict[str, Any]]
|
Current provider-native messages. |
required |
state
|
Dict[str, Any] | None
|
Optional shared provider state (available when called via ProviderWrapper). |
None
|
context
|
Optional[Dict[str, Any]]
|
Optional request/runtime context for this conversion. |
None
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
Updated provider-native messages. |
Source code in agent_core/types.py
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 | |
ProviderPlugin
Bases: BasePlugin, Protocol
Protocol for provider plugins (hot + cold paths, shared provider state).
Providers handle API I/O with LLMs and convert between core messages and provider-native messages. They run chunk processing on the hot path and participate in per-turn finalization on the cold path.
Example
Minimal echo-like provider:
from typing import Any
class EchoProvider:
name = "echo"
version = "1.0.0"
def get_config_schema(self) -> dict[str, Any]:
return {"model": {"type": "string", "default": "echo-1"}}
def init(self, config: dict[str, Any]) -> dict[str, Any]:
return {"config": config}
def call_api(
self,
native_messages: list[dict[str, Any]],
state: dict[str, Any],
):
user = next(
(
message.get("content", "")
for message in reversed(native_messages)
if message.get("role") == "user"
),
"",
)
content = f"Echo: {user}"
msg = {"role": "assistant", "content": content}
return [], [msg], [*native_messages, msg], state
The Python provider adapter supplies defaults for omitted conversion, request-initialization, finalization, and streaming hooks.
accepted_tool_schema_formats
accepted_tool_schema_formats(config, state=None)
Return schema formats this provider can send without further adaptation.
Source code in agent_core/types.py
394 395 396 397 398 399 400 | |
call_api
call_api(native_messages, state, *, request_id=None)
Make a non-streaming API call with provider-native messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
native_messages
|
List[Dict[str, Any]]
|
Provider-native input messages. |
required |
state
|
Dict[str, Any]
|
Current shared provider state. |
required |
request_id
|
str | None
|
Optional request identifier used for cancellation and diagnostics. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[List[Dict[str, Any]], List[Dict[str, Any]], List[Dict[str, Any]], Dict[str, Any]]
|
Tuple of (partial_messages, final_messages, native_messages, new_state). |
Source code in agent_core/types.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 | |
cancel_request
cancel_request(request_id)
Best-effort cancellation for an in-flight request.
Providers that track active runtime requests by request_id should
attempt to cancel the matching request and return True when a
matching in-flight request was found. Returning False indicates the
provider did not recognize the request id or had nothing active to
cancel.
Source code in agent_core/types.py
554 555 556 557 558 559 560 561 562 563 | |
emitted_tool_call_formats
emitted_tool_call_formats(config, state=None)
Return tool-call formats this provider may emit in responses.
Source code in agent_core/types.py
402 403 404 405 406 407 408 | |
finalize
finalize(native_messages, state, *, context=None)
Perform final processing after streaming completes.
The provider runs first in the finalize chain. Both final_messages and native_messages are provider-native. final_messages contains only the new messages for this turn; native_messages MUST be full history.
Active provider extensions run their finalize hooks next (in order),
followed by feature finalize hooks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
native_messages
|
List[Dict[str, Any]]
|
Full provider-native message history (all prior turns plus any for this turn). |
required |
state
|
Dict[str, Any]
|
Current shared provider state. |
required |
context
|
Optional[Dict[str, Any]]
|
Optional request context for this turn. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[List[Dict[str, Any]], List[Dict[str, Any]], Dict[str, Any]]
|
Tuple of (final_messages, native_messages, new_state). |
Source code in agent_core/types.py
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | |
from_native_messages
from_native_messages(native_messages, state, *, context=None)
Convert provider-native messages into core message dictionaries.
Note
In the default AgentCore request flow, this conversion runs
first. Active provider extensions and features may then apply
stateless transforms via their own from_native_messages hooks.
This base implementation intentionally ignores provider-specific reasoning fields. Providers and extensions that work with reasoning/thinking should surface that information via metadata (e.g., in a provider extension), not as a top-level field on the core message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
native_messages
|
List[Dict[str, Any]]
|
Provider-native messages to convert. |
required |
state
|
Dict[str, Any]
|
Current shared provider state. |
required |
context
|
Optional[Dict[str, Any]]
|
Optional request/runtime context for this conversion. |
None
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
Core messages derived from native messages. |
Source code in agent_core/types.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
get_models
get_models(config)
Return model descriptors available for this provider and config.
Each descriptor must contain a non-empty string "id". Providers
may attach additional display or capability metadata. Core preserves
those extra fields while discarding entries without a valid ID.
This hook is optional; providers may return an empty list when model enumeration is not supported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict[str, Any]
|
Effective provider configuration. |
required |
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
Model descriptor dictionaries in provider-defined order. |
Source code in agent_core/types.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 | |
get_tags
get_tags(config, models)
Return capability/environment tags for this provider.
Note
In the default AgentCore dependency-resolution flow, these tags
are aggregated with tags from provider extensions, features, and
tools to decide which plugins are enabled for a request.
Implementations must be pure and deterministic for a given (config, models) pair.
Source code in agent_core/types.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
get_tool_interop_contribution
get_tool_interop_contribution(config, state=None)
Return provider-contributed tool interop accessors/adapters.
Source code in agent_core/types.py
384 385 386 387 388 389 390 391 392 | |
init
init(config)
Initialize provider state from application config.
Note
In the default AgentCore request flow, this hook is called once
per request. Provider extensions run their init hooks after the
provider initializes, and features run their init hooks after
the provider+extensions init chain completes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict[str, Any]
|
Application-supplied configuration for the provider. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Initial shared provider state owned by the provider wrapper. |
Source code in agent_core/types.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
initialize_request
initialize_request(native_messages, state, *, request_id=None, context=None)
Prepare for a new request with provider-native messages.
Note
In the default AgentCore request flow, this hook runs first in
the initialize_request chain. Active provider extensions run
their initialize_request hooks next (in order), and feature
initialize_request hooks run after the provider (and
extensions) complete.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
native_messages
|
List[Dict[str, Any]]
|
Provider-native messages for this request. |
required |
state
|
Dict[str, Any]
|
Current shared provider state. |
required |
request_id
|
str | None
|
Optional request identifier used for cancellation and diagnostics. |
None
|
context
|
Optional[Dict[str, Any]]
|
Optional request context. The core provides keys such as
|
None
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
Tuple of (provider-native messages for this request, updated shared state). |
Dict[str, Any]
|
Implementations MAY return the same native_messages when only state changes. |
Source code in agent_core/types.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
process_chunk
process_chunk(native_chunk, native_messages, state)
Process a streaming chunk from the provider on the hot path.
Note
In the default AgentCore request flow, the provider processes
each chunk first; provider extensions are then invoked (in order)
to observe and adjust partials/finals/native history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
native_chunk
|
Dict[str, Any]
|
Provider-native streaming chunk. |
required |
native_messages
|
List[Dict[str, Any]]
|
Provider-native input messages (context). |
required |
state
|
Dict[str, Any]
|
Current shared provider state. |
required |
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
Tuple of (partial_messages, final_messages, native_messages, new_state). |
List[Dict[str, Any]]
|
native_messages MUST be the full provider-native history (not a delta). |
Source code in agent_core/types.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | |
stream_api
stream_api(native_messages, state, *, request_id=None)
Make a streaming API call; yields provider-native chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
native_messages
|
List[Dict[str, Any]]
|
Provider-native input messages. |
required |
state
|
Dict[str, Any]
|
Current shared provider state. |
required |
request_id
|
str | None
|
Optional request identifier used for cancellation and diagnostics. |
None
|
Yields:
| Type | Description |
|---|---|
Dict[str, Any]
|
Provider-native streaming chunks. |
Source code in agent_core/types.py
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 | |
to_display_format
to_display_format(message, state)
Convert a message to a display-friendly format for UIs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
Dict[str, Any]
|
Core message dictionary to format. |
required |
state
|
Dict[str, Any]
|
Current shared provider state. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Display-friendly message dictionary. |
Source code in agent_core/types.py
464 465 466 467 468 469 470 471 472 473 474 | |
to_native_messages
to_native_messages(messages, state, *, context=None)
Convert core messages to this provider's native wire format.
Note
When the core converts a single new message (e.g., via add_message), it passes a list containing only that single message in "messages". Implementations must handle both full-history lists and single-message lists.
In the default AgentCore request flow, this conversion runs
first. Active provider extensions and features may then apply
stateless transforms via their own to_native_messages hooks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
List[Dict[str, Any]]
|
Core session messages (may be a single-element list for add_message). |
required |
state
|
Dict[str, Any]
|
Current shared provider state. |
required |
context
|
Optional[Dict[str, Any]]
|
Optional request/runtime context for this conversion. |
None
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
Provider-native messages suitable for API calls. |
Source code in agent_core/types.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
ProviderRequestCancelled
ProviderRequestCancelled(request_id=None)
Bases: RuntimeError
Raised when a provider request is cancelled.
Attributes:
| Name | Type | Description |
|---|---|---|
request_id |
Optional identifier of the cancelled request. |
Source code in agent_core/types.py
77 78 79 | |
Session
dataclass
Session(session_id, messages=list(), metadata=dict())
Frozen conversation value managed by an application.
The dataclass prevents field reassignment. messages and metadata
remain mutable Python containers and must be treated as immutable by
convention. Use AgentCore session/message operations to return updated
sessions instead of modifying either container in place.
Attributes:
| Name | Type | Description |
|---|---|---|
session_id |
str
|
Unique identifier for this session. |
messages |
List[Message]
|
Ordered completed core messages. |
metadata |
Dict[str, Any]
|
Session-level application and provider metadata. Core may retain provider-native history and its integrity data here; those keys are implementation-managed rather than a portable message schema. |
Examples:
>>> session = Session(session_id="test", messages=[])
>>> len(session.messages)
0
from_dict
classmethod
from_dict(data)
Create a session from a dictionary representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dict[str, Any]
|
Dictionary containing session_id, messages, and optional metadata. |
required |
Returns:
| Type | Description |
|---|---|
Session
|
New Session instance. |
Source code in agent_core/types.py
2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 | |
to_dict
to_dict()
Return a serializable dictionary representation.
Messages are converted with :meth:Message.to_dict, and session
metadata is deep copied.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary representation of the session. |
Source code in agent_core/types.py
2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 | |
ToolDescriptor
dataclass
ToolDescriptor(plugin_name, tool_name, schema, metadata=dict())
Core's normalized description of one available tool schema.
Attributes:
| Name | Type | Description |
|---|---|---|
plugin_name |
str
|
Name of the tool plugin that contributed the schema. |
tool_name |
str
|
Semantic tool/function name extracted through tool interop. |
schema |
Dict[str, Any]
|
Original schema dictionary contributed by the tool or config. |
metadata |
Dict[str, Any]
|
Additional Core or interop metadata such as schema position and source. Callers should treat it as immutable. |
ToolPlugin
Bases: BasePlugin, Protocol
Protocol for tool plugins (own tool state; unchanged by shared state design).
Tools provide function schemas and handle execution with their own state, independent from the provider shared state.
Example
Minimal calculator tool:
class DummyCalc:
name = "calculator"
version = "1.0.0"
def get_tool_schemas(self, state):
return [{"type": "function", "function": {"name": "add", "parameters": {"type": "object", "properties": {"a": {"type": "number"}, "b": {"type": "number"}}, "required": ["a","b"]}}}]
def init(self, config):
return {"config": config}
def execute_tool(self, tool_name, arguments, state):
if tool_name == "add":
return {"success": True, "result": arguments.get("a", 0) + arguments.get("b", 0)}
return {"success": False, "error": "unknown"}
def format_tool_result(self, result, state):
return f"Result: {result['result']}" if result.get("success") else f"Error: {result.get('error')}"
can_handle_tool_call
can_handle_tool_call(tool_name, payload, state, *, payload_kind=None, payload_format=None, payload_metadata=None, tool_call=None, tool_schema=None, prepared=None)
Return whether this tool can handle the inspected tool call.
None means no opinion and allows legacy name-based fallback.
Source code in agent_core/types.py
1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 | |
execute_tool
execute_tool(tool_name, payload, state, *, payload_kind=None, payload_format=None, payload_metadata=None, tool_call=None, cancellation=None, context=None, prepared=None)
Execute a tool call using the final payload object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_name
|
Optional[str]
|
Name of the tool/function when available. |
required |
payload
|
Any
|
Final payload for the tool call, such as a dict or raw text. |
required |
state
|
Dict[str, Any]
|
Current tool state. |
required |
payload_kind
|
Optional[str]
|
Optional semantic payload kind such as |
None
|
payload_format
|
Optional[str]
|
Optional format identifier for the payload itself. |
None
|
payload_metadata
|
Optional[Dict[str, Any]]
|
Optional extra payload metadata from the accessor. |
None
|
tool_call
|
Optional[Dict[str, Any]]
|
Optional original tool-call dict. |
None
|
cancellation
|
Any | None
|
Optional cooperative cancellation controller. |
None
|
context
|
Optional[Dict[str, Any]]
|
Optional layered context providing access to runtime capabilities. |
None
|
prepared
|
Optional[Dict[str, Any]]
|
Optional JSON-like prepared data returned by
:meth: |
None
|
The context parameter provides layered access to runtime capabilities:
Layer 1 (Core - always present when called from AgentCore):
- core: AgentCore instance for session/message operations and LLM calls
- config: Current resolved request configuration
- trigger_source: Where the tool was triggered ("core")
- session: Serialized session dict (session.to_dict()) when available
Layer 2 (Application - when called from AgentApplication):
- app and application: AgentApplication instance
- base_config: Full base configuration (all agents)
- session_asset_store: Session asset store for file attachments
- runtime_state_root: Persistent runtime-state root directory
Caller-supplied context is additive only. Reserved keys owned by the context builders are not overridden; on clashes the builder keeps the owned value and emits a warning.
Tools can use context to make LLM calls::
core = (context or {}).get("core")
if core:
temp_session = core.create_session()
events = core.send_request_stream(temp_session, config)
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Result dictionary, e.g., {"success": bool, "result": any, "error": str}. |
Source code in agent_core/types.py
1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 | |
execute_tool_async
async
execute_tool_async(tool_name, payload, state, *, payload_kind=None, payload_format=None, payload_metadata=None, tool_call=None, cancellation=None, context=None, prepared=None)
Optional async execution hook for tool authors using async libraries.
Source code in agent_core/types.py
1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 | |
forbidden_tags
forbidden_tags()
Tags that must NOT be present for this tool to be exposed.
If any of these tags are in the available tag set, the tool is disabled. This provides a negative constraint complementary to required_tags.
Source code in agent_core/types.py
1568 1569 1570 1571 1572 1573 1574 | |
format_tool_call_preview
format_tool_call_preview(tool_name, payload, state, *, payload_kind=None, payload_format=None, payload_metadata=None, tool_call=None, prepared=None)
Generate a pre-execution preview for a tool call.
This hook is invoked when an assistant message containing tool calls is finalized, before the tools are executed. It should return a brief summary of what the tool call will do.
The preview is intended for human-facing UIs (e.g. a collapsible list of tool calls) and should not be used for model-facing tool output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_name
|
Optional[str]
|
Name of the tool/function when available. |
required |
payload
|
Any
|
Final payload for the tool call. |
required |
state
|
Dict[str, Any]
|
Current tool state. |
required |
prepared
|
Optional[Dict[str, Any]]
|
Optional JSON-like prepared data returned by
:meth: |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A short string (preferably single-line). Return an empty string when |
str
|
no preview is available. |
Source code in agent_core/types.py
1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 | |
format_tool_result
format_tool_result(result, state)
Format a tool result dictionary for LLM consumption/display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
Dict[str, Any]
|
Tool execution result dictionary. |
required |
state
|
Dict[str, Any]
|
Current tool state. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Human-readable string representation or an explicit provider-native |
Any
|
tool result payload. |
Source code in agent_core/types.py
1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 | |
get_tags
get_tags(config, models)
Return capability/environment tags contributed by this tool.
Note
In the default AgentCore dependency-resolution flow, these tags
are aggregated with tags from the provider, provider extensions, and
features to decide which tools are exposed.
Source code in agent_core/types.py
1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 | |
get_tool_interop_contribution
get_tool_interop_contribution(state)
Return tool-contributed tool interop accessors/adapters.
Source code in agent_core/types.py
1651 1652 1653 1654 1655 1656 1657 1658 | |
get_tool_schemas
get_tool_schemas(state, *, prepared=None)
Return tool schemas provided by this tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
Dict[str, Any]
|
Current tool state (if needed by the tool). |
required |
prepared
|
Optional[Dict[str, Any]]
|
Optional JSON-like prepared data returned by
:meth: |
None
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List of tool definition dictionaries in any format understood by the |
List[Dict[str, Any]]
|
active interop accessors/adapters. |
Source code in agent_core/types.py
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 | |
init
init(config)
Initialize internal tool state from application config.
Note
In the default AgentCore request flow, tools are initialized
before the provider so their tool schemas can be injected into the
provider config under the "tools" key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict[str, Any]
|
Application-supplied configuration for the tool. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Initial tool state dictionary. |
Source code in agent_core/types.py
1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 | |
is_enabled
is_enabled(config, tags, models, context)
Return whether this tool should be enabled given the current context.
This method allows tools to implement complex enablement logic that goes beyond simple tag matching. It receives the full runtime context including configuration, computed tags, model descriptors, and information about other enabled plugins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Dict[str, Any]
|
Effective configuration for the current request. |
required |
tags
|
List[str]
|
Capability tags computed for this config. |
required |
models
|
List[Dict[str, Any]]
|
Model descriptors computed for this config. |
required |
context
|
Dict[str, Any]
|
Additional context including: - "enabled_plugin_ids": dict mapping plugin kind to list of enabled plugin ids - "disabled_plugins": config-level disabled plugin id list - "force_enabled_plugins": config-level force-enabled plugin id list |
required |
Returns:
| Name | Type | Description |
|---|---|---|
True |
Optional[bool]
|
tool is enabled (bypass required_tags/forbidden_tags check) |
False |
Optional[bool]
|
tool is disabled |
None |
Optional[bool]
|
fall back to required_tags/forbidden_tags check (default) |
Source code in agent_core/types.py
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 | |
prepare
prepare(config, state, *, context=None)
Perform optional long-running preparation for later cheap hooks.
prepare is separate from :meth:init so callers can keep schema
discovery and preview helpers cheap by default. Implementations may do
I/O, subprocess startup, discovery, or cache hydration here, but should
return only JSON-like prepared data.
Source code in agent_core/types.py
1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 | |
prepare_async
async
prepare_async(config, state, *, context=None)
Async variant of :meth:prepare with identical semantics.
Source code in agent_core/types.py
1622 1623 1624 1625 1626 1627 1628 1629 1630 | |
required_tags
required_tags()
Tags that must be present for this tool to be exposed.
Source code in agent_core/types.py
1564 1565 1566 | |
stream_tool
stream_tool(tool_name, payload, state, *, payload_kind=None, payload_format=None, payload_metadata=None, tool_call=None, cancellation=None, context=None, prepared=None)
Optional streaming execution hook for tools.
Default implementation yields nothing. Concrete tools may override this to provide incremental, display-oriented results for long-running operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_name
|
Optional[str]
|
Name of the tool/function when available. |
required |
payload
|
Any
|
Final payload for the tool call. |
required |
state
|
Dict[str, Any]
|
Current tool state. |
required |
payload_kind
|
Optional[str]
|
Optional semantic payload kind. |
None
|
payload_format
|
Optional[str]
|
Optional format identifier for the payload. |
None
|
payload_metadata
|
Optional[Dict[str, Any]]
|
Optional extra payload metadata. |
None
|
tool_call
|
Optional[Dict[str, Any]]
|
Optional original tool-call dict. |
None
|
cancellation
|
Any | None
|
Optional cancellation token. |
None
|
context
|
Optional[Dict[str, Any]]
|
Optional layered context providing access to runtime capabilities.
See :meth: |
None
|
prepared
|
Optional[Dict[str, Any]]
|
Optional JSON-like prepared data returned by
:meth: |
None
|
Yields:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary chunks with partial results ({"part": ...}) or final |
Dict[str, Any]
|
result ({"success": bool, ...}). |
Source code in agent_core/types.py
1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 | |
stream_tool_async
async
stream_tool_async(tool_name, payload, state, *, payload_kind=None, payload_format=None, payload_metadata=None, tool_call=None, cancellation=None, context=None, prepared=None)
Optional async streaming hook for tool authors using async libraries.
Source code in agent_core/types.py
1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 | |
to_display_format
to_display_format(text, result, state)
Optional display conversion hook for tool results.
Default implementation wraps the formatted text in a simple
{"type": "text", "content": text} payload suitable for UIs.
Tools may optionally include a "single_line" field in the returned
dict to provide a compact summary for collapsed/short views:
{"type": "text", "content": <full>, "single_line": <compact>}.
The single_line field should contain a brief preview (e.g., just the
command for shell tools, or a list of changed files for patch tools)
that UIs can display when tool results are collapsed or shown in short
mode. When expanded, UIs should use content for the full result.
Source code in agent_core/types.py
1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 | |