Skip to content

Commit 2ced8d1

Browse files
committed
feat(ptc): add Python runtime support
Add Python as a PTC execution language while preserving TypeScript as the legacy ptc mode. - Route local and remote RunCode execution through the Python runtime - Generate typed Python SDK declarations and language-neutral tool specs - Persist the ptc_python presentation mode for new and existing session flows - Preserve PTC language metadata for replayed RunCode cards - Add runtime, contract, pipeline, and product-control coverage
1 parent c280299 commit 2ced8d1

28 files changed

Lines changed: 1863 additions & 92 deletions

File tree

‎docs/interactive-capabilities/capabilities.json‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"title": "OpenBitFun Playbook",
55
"origin": "https://playbook.openbitfun.com",
66
"source": "src/shared/interactive-capabilities/catalog.json",
7-
"digest": "5c26d781f664b1daa3cef9062f0ad3e776544242b80fbd1fc303d59d4494eed3",
8-
"ownerDigest": "0b2d30952efd57108d9e566dc0bf5a176f2b3d753abfb736bfc32b2c1fa3f7b7",
7+
"digest": "513e184cc2d93f183cdea258516f532caf58ac6400ef76dce9b54f6de0752627",
8+
"ownerDigest": "3cc6d7d869b2c90c2161494a854b5ff7eb72ea69a1a28e40ccd42065fb3382e2",
99
"searchAcceptance": [
1010
{
1111
"id": "native-image-generation",
@@ -16923,7 +16923,8 @@
1692316923
"type": "string",
1692416924
"enum": [
1692516925
"native",
16926-
"ptc"
16926+
"ptc",
16927+
"ptc_python"
1692716928
]
1692816929
},
1692916930
"outputSchema": {
@@ -30162,8 +30163,8 @@
3016230163
},
3016330164
{
3016430165
"id": "tool-presentation",
30165-
"titleZh": "选择模型使用原生模式还是 PTC TypeScript 模式",
30166-
"titleEn": "Choose native mode or PTC TypeScript mode for the model",
30166+
"titleZh": "选择模型使用原生模式、PTC TypeScript 或 PTC Python 模式",
30167+
"titleEn": "Choose native, PTC TypeScript, or PTC Python mode for the model",
3016730168
"destination": {
3016830169
"kind": "settings",
3016930170
"pageId": "tools.execution",
@@ -30359,13 +30360,14 @@
3035930360
"id": "tool-presentation-mode",
3036030361
"titleZh": "工具呈现模式",
3036130362
"titleEn": "Tool presentation mode",
30362-
"descriptionZh": "选择模型直接调用原生工具,或通过 PTC TypeScript 调用工具。",
30363-
"descriptionEn": "Choose whether the model calls native tools directly or uses PTC TypeScript.",
30363+
"descriptionZh": "选择模型直接调用原生工具,或通过 PTC TypeScript/Python 调用工具。",
30364+
"descriptionEn": "Choose whether the model calls native tools directly or uses PTC TypeScript or Python.",
3036430365
"valueSchema": {
3036530366
"type": "string",
3036630367
"enum": [
3036730368
"native",
30368-
"ptc"
30369+
"ptc",
30370+
"ptc_python"
3036930371
]
3037030372
}
3037130373
},
@@ -30496,8 +30498,8 @@
3049630498
"Review, revoke, or clear remembered project permission grants and audit records",
3049730499
"按需延迟加载工具定义以减少智能体初始上下文",
3049830500
"Deferred tool loading on demand to reduce initial agent context",
30499-
"选择模型使用原生模式还是 PTC TypeScript 模式",
30500-
"Choose native mode or PTC TypeScript mode for the model",
30501+
"选择模型使用原生模式、PTC TypeScript 或 PTC Python 模式",
30502+
"Choose native, PTC TypeScript, or PTC Python mode for the model",
3050130503
"设置子智能体与 Swarm 最大并发及安全、强制并行或串行策略",
3050230504
"Set subagent and swarm concurrency plus safe-only, forced-parallel, or serial policy",
3050330505
"设置或取消单次工具调用超时",

‎docs/interactive-capabilities/capabilities/setting.tools.execution.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ Manage agent tool permissions, presentation mode, concurrency, timeouts, deferre
2727
- Review, revoke, or clear remembered project permission grants and audit records
2828
- **智能体可直接控制 / Direct Agent control** · 按需延迟加载工具定义以减少智能体初始上下文
2929
- Deferred tool loading on demand to reduce initial agent context
30-
- **智能体可直接控制 / Direct Agent control** · 选择模型使用原生模式还是 PTC TypeScript 模式
31-
- Choose native mode or PTC TypeScript mode for the model
30+
- **智能体可直接控制 / Direct Agent control** · 选择模型使用原生模式、PTC TypeScript 或 PTC Python 模式
31+
- Choose native, PTC TypeScript, or PTC Python mode for the model
3232
- **智能体可直接控制 / Direct Agent control** · 设置子智能体与 Swarm 最大并发及安全、强制并行或串行策略
3333
- Set subagent and swarm concurrency plus safe-only, forced-parallel, or serial policy
3434
- **智能体可直接控制 / Direct Agent control** · 设置或取消单次工具调用超时
@@ -69,7 +69,7 @@ Manage agent tool permissions, presentation mode, concurrency, timeouts, deferre
6969
| --- | --- | --- | --- |
7070
| 显示权限模式选择器 / Show permission-mode selector | `boolean` | 在聊天输入框下方显示或隐藏权限模式快捷选择器。 | Show or hide the permission-mode shortcut below the chat composer. |
7171
| 延迟加载工具 / Deferred tool loading | `boolean` | 按需加载大型工具定义,减少智能体初始上下文。 | Load large tool definitions on demand to reduce initial agent context. |
72-
| 工具呈现模式 / Tool presentation mode | `native` / `ptc` | 选择模型直接调用原生工具,或通过 PTC TypeScript 调用工具。 | Choose whether the model calls native tools directly or uses PTC TypeScript. |
72+
| 工具呈现模式 / Tool presentation mode | `native` / `ptc` / `ptc_python` | 选择模型直接调用原生工具,或通过 PTC TypeScript/Python 调用工具。 | Choose whether the model calls native tools directly or uses PTC TypeScript or Python. |
7373
| 子智能体批量执行策略 / Subagent batch policy | `safe_only` / `force_parallel` / `serial` | 选择仅安全任务并行、强制并行或串行执行。 | Choose safe-only parallelism, forced parallelism, or serial execution. |
7474
| 子智能体最大并发 / Maximum subagent concurrency | `integer` (1–32) | 限制同时运行的子智能体数量。 | Limit the number of subagents that may run at once. |
7575
| Swarm 最大并发 / Maximum swarm concurrency | `integer` (1–64) | 限制 Swarm 中同时执行的工作单元。 | Limit concurrent work units inside a swarm. |

‎docs/interactive-capabilities/technical/product-control-open-audit.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"schemaVersion": 1,
33
"generatedFrom": "src/shared/interactive-capabilities/catalog.json",
4-
"catalogDigest": "5c26d781f664b1daa3cef9062f0ad3e776544242b80fbd1fc303d59d4494eed3",
4+
"catalogDigest": "513e184cc2d93f183cdea258516f532caf58ac6400ef76dce9b54f6de0752627",
55
"count": 204,
66
"reasonCounts": {
77
"externalAuth": 4,

‎docs/interactive-capabilities/technical/tauri-command-map.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"schemaVersion": 2,
33
"generatedFrom": "src/shared/interactive-capabilities/catalog.json",
4-
"catalogDigest": "5c26d781f664b1daa3cef9062f0ad3e776544242b80fbd1fc303d59d4494eed3",
4+
"catalogDigest": "513e184cc2d93f183cdea258516f532caf58ac6400ef76dce9b54f6de0752627",
55
"commandCount": 709,
66
"coverage": {
77
"commandCount": 709,

‎scripts/core-boundaries/rules/feature-rules.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export const optionalDependencyFeatureOwnerRules = [
291291
{ depName: 'openbitfun-agent-workflows', ownerFeatures: ['deep-research'] },
292292
{
293293
depName: 'openbitfun-core-types',
294-
ownerFeatures: ['deep-research', 'remote-connect', 'remote-ssh-concrete', 'speech'],
294+
ownerFeatures: ['deep-research', 'ptc-runtime', 'remote-connect', 'remote-ssh-concrete', 'speech'],
295295
},
296296
{ depName: 'openbitfun-product-domains', ownerFeatures: ['account-identity', 'canvas-runtime', 'function-agents', 'hook-import', 'miniapp-market', 'miniapp-runtime', 'miniapp-storage', 'plugin-source', 'remote-connect'] },
297297
{ depName: 'openbitfun-runtime-ports', ownerFeatures: ['deep-research', 'git', 'ptc-runtime', 'remote-connect', 'remote-ssh', 'remote-ssh-concrete', 'script-tool-runtime', 'web-tools'] },

‎src/crates/assembly/core/src/agentic/coordination/coordinator.rs‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ use openbitfun_agent_runtime::remote_file_delivery::{
103103
};
104104
use openbitfun_agent_runtime::sdk::PermissionReply;
105105
use openbitfun_agent_runtime::user_questions::USER_INPUT_AVAILABLE_CONTEXT_KEY;
106-
use openbitfun_agent_tools::{PTC_TOOL_PRESENTATION_CONTEXT_KEY, PTC_TOOL_PRESENTATION_MODE};
106+
use openbitfun_agent_tools::{
107+
PTC_LANGUAGE_CONTEXT_KEY, PTC_TOOL_PRESENTATION_CONTEXT_KEY, PTC_TOOL_PRESENTATION_MODE,
108+
};
107109
use openbitfun_config_contracts::model_pool::AgentModelSelection;
108110
use openbitfun_config_contracts::model_pool::AgentModelSelections;
109111
use openbitfun_core_types::model_pool::ModelSelection;
@@ -7339,6 +7341,15 @@ Update the persona files and delete BOOTSTRAP.md as soon as bootstrap is complet
73397341
PTC_TOOL_PRESENTATION_CONTEXT_KEY.to_string(),
73407342
PTC_TOOL_PRESENTATION_MODE.to_string(),
73417343
);
7344+
context_vars.insert(
7345+
PTC_LANGUAGE_CONTEXT_KEY.to_string(),
7346+
session
7347+
.config
7348+
.tool_presentation_mode
7349+
.language()
7350+
.as_str()
7351+
.to_string(),
7352+
);
73427353
}
73437354
let review_agent = is_review_agent_type(&effective_agent_type);
73447355
let turn_review_manifest =
@@ -7951,6 +7962,15 @@ Update the persona files and delete BOOTSTRAP.md as soon as bootstrap is complet
79517962
PTC_TOOL_PRESENTATION_CONTEXT_KEY.to_string(),
79527963
PTC_TOOL_PRESENTATION_MODE.to_string(),
79537964
);
7965+
context_vars.insert(
7966+
PTC_LANGUAGE_CONTEXT_KEY.to_string(),
7967+
session
7968+
.config
7969+
.tool_presentation_mode
7970+
.language()
7971+
.as_str()
7972+
.to_string(),
7973+
);
79547974
}
79557975
if let Some(user_input_available) = metadata_bool(
79567976
plan.user_message_metadata.as_ref(),

‎src/crates/assembly/core/src/agentic/tools/openbitfun_control_config.rs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,25 @@ mod tests {
785785
.expect("tool presentation mode is config-backed");
786786
assert_eq!(applied.changed_path, "ai.tool_presentation_mode");
787787
assert_eq!(applied.effective_value, Value::String("ptc".to_string()));
788+
789+
let applied_python = configure_config_backed_option(
790+
&service,
791+
option,
792+
&Value::String("ptc_python".to_string()),
793+
)
794+
.await
795+
.expect("PTC Python should be accepted")
796+
.expect("tool presentation mode is config-backed");
797+
assert_eq!(
798+
applied_python.effective_value,
799+
Value::String("ptc_python".to_string())
800+
);
801+
assert_eq!(
802+
read_config_backed_option(&service, option)
803+
.await
804+
.expect("PTC Python should be readable"),
805+
Some(Value::String("ptc_python".to_string()))
806+
);
788807
}
789808

790809
#[tokio::test]

‎src/crates/assembly/core/src/agentic/tools/pipeline/tool_pipeline.rs‎

Lines changed: 100 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ use openbitfun_agent_tools::{
3232
build_tool_execution_timeout_presentation,
3333
build_user_rejected_tool_presentation_with_instruction,
3434
build_user_steering_interrupted_presentation, build_write_tail_closure_notice,
35-
render_ptc_loaded_tool_typescript_sdk, render_tool_result_for_assistant,
35+
render_ptc_loaded_tool_sdk, render_tool_result_for_assistant,
3636
validate_tool_execution_admission, DynamicToolInfo, LoadedDeferredToolSpec, PermissionIntent,
3737
PtcToolContract, ResolvedToolInvocation, ToolExecutionAdmissionRejection,
3838
ToolExecutionAdmissionRequest, ToolExecutionErrorPresentation, CALL_DEFERRED_TOOL_NAME,
39-
GET_TOOL_SPEC_TOOL_NAME, PTC_NESTED_ALLOWED_TOOLS_CONTEXT_KEY,
39+
GET_TOOL_SPEC_TOOL_NAME, PTC_LANGUAGE_CONTEXT_KEY, PTC_NESTED_ALLOWED_TOOLS_CONTEXT_KEY,
4040
USER_STEERING_INTERRUPTED_MESSAGE,
4141
};
42+
#[cfg(feature = "ptc-runtime")]
43+
use openbitfun_core_types::PtcLanguage;
4244
use openbitfun_runtime_ports::{
4345
PermissionReply, PermissionRequest, PermissionRequestSource, PermissionRequestSourceKind,
4446
PermissionResourceCaseSensitivity, RoundInjectionToolPreemption,
@@ -50,6 +52,8 @@ use openbitfun_runtime_ports::{
5052
};
5153
#[cfg(feature = "ptc-runtime")]
5254
use openbitfun_services_integrations::ptc_runtime::NodePtcRuntime;
55+
#[cfg(feature = "ptc-runtime")]
56+
use openbitfun_services_integrations::python_ptc_runtime::PythonPtcRuntime;
5357
use std::collections::{HashMap, HashSet};
5458
use std::sync::Arc;
5559
use std::time::{Instant, SystemTime};
@@ -183,9 +187,13 @@ fn convert_tool_result_with_metadata(
183187
// "completed successfully" can hide fields the model needs for the
184188
// next decision.
185189
let assistant_text = result_for_assistant.or_else(|| {
190+
let mut assistant_visible_data = assistant_data.clone();
191+
if let Some(object) = assistant_visible_data.as_object_mut() {
192+
object.remove("__ptc_language");
193+
}
186194
Some(render_tool_result_for_assistant(
187195
effective_tool_name,
188-
&assistant_data,
196+
&assistant_visible_data,
189197
))
190198
});
191199
// Tools with a typed response envelope can report a recoverable
@@ -754,6 +762,14 @@ struct PtcPipelineToolCallHandler {
754762
loaded_deferred_tool_specs: Arc<TokioMutex<Vec<LoadedDeferredToolSpec>>>,
755763
}
756764

765+
#[cfg(feature = "ptc-runtime")]
766+
fn build_ptc_tool_spec_response(language: PtcLanguage, sdk_source: String) -> serde_json::Value {
767+
serde_json::json!({
768+
"language": language.as_str(),
769+
"sdk_source": sdk_source,
770+
})
771+
}
772+
757773
#[cfg(feature = "ptc-runtime")]
758774
#[async_trait::async_trait]
759775
impl PtcToolCallHandler for PtcPipelineToolCallHandler {
@@ -886,12 +902,20 @@ impl PtcToolCallHandler for PtcPipelineToolCallHandler {
886902
.cloned()
887903
.unwrap_or_else(|| serde_json::json!({}));
888904
let output_schema = tool.output_schema();
889-
let typescript_sdk = render_ptc_loaded_tool_typescript_sdk(&PtcToolContract::new(
890-
tool_name.clone(),
891-
description,
892-
input_schema,
893-
output_schema,
894-
));
905+
let language = if self
906+
.context
907+
.context_vars
908+
.get(PTC_LANGUAGE_CONTEXT_KEY)
909+
.is_some_and(|language| language.eq_ignore_ascii_case("python"))
910+
{
911+
PtcLanguage::Python
912+
} else {
913+
PtcLanguage::TypeScript
914+
};
915+
let sdk_source = render_ptc_loaded_tool_sdk(
916+
&PtcToolContract::new(tool_name.clone(), description, input_schema, output_schema),
917+
language,
918+
);
895919

896920
let mut loaded = self.loaded_deferred_tool_specs.lock().await;
897921
if let Some(existing) = loaded.iter_mut().find(|spec| spec.tool_name == tool_name) {
@@ -902,9 +926,7 @@ impl PtcToolCallHandler for PtcPipelineToolCallHandler {
902926
catalog_generation,
903927
});
904928
}
905-
Ok(serde_json::json!({
906-
"typescript_sdk": typescript_sdk,
907-
}))
929+
Ok(build_ptc_tool_spec_response(language, sdk_source))
908930
}
909931
}
910932

@@ -2974,7 +2996,12 @@ impl ToolPipeline {
29742996
.effective_arguments()
29752997
.get("timeout_ms")
29762998
.and_then(serde_json::Value::as_u64);
2977-
let runtime = if context.is_remote() {
2999+
let use_python = context
3000+
.custom_data
3001+
.get(PTC_LANGUAGE_CONTEXT_KEY)
3002+
.and_then(serde_json::Value::as_str)
3003+
.is_some_and(|language| language.eq_ignore_ascii_case("python"));
3004+
let runtime: Box<dyn PtcRuntime> = if context.is_remote() {
29783005
#[cfg(feature = "ssh-remote")]
29793006
{
29803007
let workspace = context.workspace.as_ref().ok_or_else(|| {
@@ -3002,7 +3029,11 @@ impl ToolPipeline {
30023029
"Remote SSH services are not initialized".to_string(),
30033030
)
30043031
})?;
3005-
NodePtcRuntime::for_remote(ssh_manager, connection_id)
3032+
if use_python {
3033+
Box::new(PythonPtcRuntime::for_remote(ssh_manager, connection_id))
3034+
} else {
3035+
Box::new(NodePtcRuntime::for_remote(ssh_manager, connection_id))
3036+
}
30063037
}
30073038
#[cfg(not(feature = "ssh-remote"))]
30083039
{
@@ -3011,7 +3042,11 @@ impl ToolPipeline {
30113042
));
30123043
}
30133044
} else {
3014-
NodePtcRuntime::discover()
3045+
if use_python {
3046+
Box::new(PythonPtcRuntime::discover())
3047+
} else {
3048+
Box::new(NodePtcRuntime::discover())
3049+
}
30153050
};
30163051
let operation_id = task.tool_call.tool_id.clone();
30173052
let handler = Arc::new(PtcPipelineToolCallHandler {
@@ -3055,6 +3090,34 @@ impl ToolPipeline {
30553090
"logs": response.logs,
30563091
})
30573092
};
3093+
// Persist the source language alongside the result so replayed RunCode
3094+
// cards can select the correct syntax highlighter even though the
3095+
// provider's original arguments only contain `code`.
3096+
let ptc_language = context
3097+
.custom_data
3098+
.get(PTC_LANGUAGE_CONTEXT_KEY)
3099+
.map(|value| {
3100+
if value
3101+
.as_str()
3102+
.is_some_and(|value| value.eq_ignore_ascii_case("python"))
3103+
{
3104+
PtcLanguage::Python
3105+
} else {
3106+
PtcLanguage::TypeScript
3107+
}
3108+
})
3109+
.unwrap_or_default();
3110+
if let Some(object) = data.as_object_mut() {
3111+
object.insert(
3112+
"__ptc_language".to_string(),
3113+
serde_json::Value::String(ptc_language.as_str().to_string()),
3114+
);
3115+
} else {
3116+
data = serde_json::json!({
3117+
"value": data,
3118+
"__ptc_language": ptc_language.as_str(),
3119+
});
3120+
}
30583121
let loaded_deferred_tool_specs = handler.loaded_deferred_tool_specs.lock().await.clone();
30593122
if !loaded_deferred_tool_specs.is_empty() {
30603123
let loaded_specs_value = serde_json::to_value(&loaded_deferred_tool_specs)
@@ -4359,6 +4422,23 @@ mod tests {
43594422
}));
43604423
}
43614424

4425+
#[cfg(feature = "ptc-runtime")]
4426+
#[test]
4427+
fn ptc_tool_spec_response_uses_one_language_neutral_sdk_field() {
4428+
for language in [PtcLanguage::TypeScript, PtcLanguage::Python] {
4429+
let response = build_ptc_tool_spec_response(language, "sdk".to_string());
4430+
assert_eq!(
4431+
response,
4432+
json!({
4433+
"language": language.as_str(),
4434+
"sdk_source": "sdk",
4435+
})
4436+
);
4437+
assert!(response.get("typescript_sdk").is_none());
4438+
assert!(response.get("python_sdk").is_none());
4439+
}
4440+
}
4441+
43624442
#[cfg(feature = "ptc-runtime")]
43634443
#[tokio::test]
43644444
async fn ptc_run_code_dispatches_nested_calls_through_the_pipeline() {
@@ -4396,7 +4476,11 @@ mod tests {
43964476
results[0].tool_name,
43974477
openbitfun_agent_tools::PTC_RUN_CODE_TOOL_NAME
43984478
);
4399-
assert_eq!(results[0].result.result, json!({"content": "ok"}));
4479+
assert_eq!(results[0].result.result["content"], json!("ok"));
4480+
assert_eq!(
4481+
results[0].result.result["__ptc_language"],
4482+
json!("typescript")
4483+
);
44004484

44014485
let nested = pipeline
44024486
.state_manager

0 commit comments

Comments
 (0)