feat(agent-runner): expose effective prompt pull api

This commit is contained in:
huanghuoguoguo
2026-06-13 15:31:54 +08:00
parent 3984e0fe40
commit d0b0a682c7
6 changed files with 77 additions and 2 deletions

View File

@@ -422,6 +422,7 @@ class AgentRunContextBuilder:
'reason': 'current_event_only',
},
'available_apis': {
'prompt_get': False,
'history_page': history_page_enabled,
'history_search': history_search_enabled,
'event_get': event_get_enabled,

View File

@@ -96,6 +96,8 @@ class AgentRunOrchestrator:
context.get('state', {}),
)
session_query_id = adapter_context.get('query_id')
if query is not None or session_query_id is not None:
context['context']['available_apis']['prompt_get'] = True
if 'params' in adapter_context:
context['adapter']['extra']['params'] = adapter_context['params']

View File

@@ -1506,6 +1506,40 @@ class RuntimeConnectionHandler(handler.Handler):
# ================= Agent History/Event APIs =================
@self.action(PluginToRuntimeAction.GET_PROMPT)
async def get_prompt(data: dict[str, Any]) -> handler.ActionResponse:
"""Return the current run's effective prompt after PromptPreProcessing."""
run_id = data.get('run_id')
caller_plugin_identity = data.get('caller_plugin_identity')
if not run_id:
return handler.ActionResponse.error(message='run_id is required')
session, error = await _validate_agent_run_session(
run_id,
caller_plugin_identity,
self.ap,
'Get prompt',
api_capability='prompt_get',
)
if error:
return error
query = _resolve_action_query(data, session, self.ap)
if query is None:
return handler.ActionResponse.error(
message=f'Query for run_id {run_id} not found or expired',
)
prompt = getattr(query, 'prompt', None)
messages = getattr(prompt, 'messages', []) or []
return handler.ActionResponse.success(data={
'prompt': [
message.model_dump(mode='json') if hasattr(message, 'model_dump') else message
for message in messages
],
})
@self.action(PluginToRuntimeAction.HISTORY_PAGE)
async def history_page(data: dict[str, Any]) -> handler.ActionResponse:
"""Page through transcript history for a conversation.