AbstractRuntime 0.0.1__py3-none-any.whl → 0.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- abstractruntime/__init__.py +7 -2
- abstractruntime/core/__init__.py +9 -2
- abstractruntime/core/config.py +114 -0
- abstractruntime/core/event_keys.py +62 -0
- abstractruntime/core/models.py +55 -1
- abstractruntime/core/runtime.py +2609 -24
- abstractruntime/core/vars.py +189 -0
- abstractruntime/evidence/__init__.py +10 -0
- abstractruntime/evidence/recorder.py +325 -0
- abstractruntime/integrations/abstractcore/__init__.py +9 -2
- abstractruntime/integrations/abstractcore/constants.py +19 -0
- abstractruntime/integrations/abstractcore/default_tools.py +134 -0
- abstractruntime/integrations/abstractcore/effect_handlers.py +288 -9
- abstractruntime/integrations/abstractcore/factory.py +133 -11
- abstractruntime/integrations/abstractcore/llm_client.py +547 -42
- abstractruntime/integrations/abstractcore/mcp_worker.py +586 -0
- abstractruntime/integrations/abstractcore/observability.py +80 -0
- abstractruntime/integrations/abstractcore/summarizer.py +154 -0
- abstractruntime/integrations/abstractcore/tool_executor.py +544 -8
- abstractruntime/memory/__init__.py +21 -0
- abstractruntime/memory/active_context.py +746 -0
- abstractruntime/memory/active_memory.py +452 -0
- abstractruntime/memory/compaction.py +105 -0
- abstractruntime/rendering/__init__.py +17 -0
- abstractruntime/rendering/agent_trace_report.py +256 -0
- abstractruntime/rendering/json_stringify.py +136 -0
- abstractruntime/scheduler/scheduler.py +93 -2
- abstractruntime/storage/__init__.py +3 -1
- abstractruntime/storage/artifacts.py +51 -5
- abstractruntime/storage/json_files.py +16 -3
- abstractruntime/storage/observable.py +99 -0
- {abstractruntime-0.0.1.dist-info → abstractruntime-0.4.0.dist-info}/METADATA +5 -1
- abstractruntime-0.4.0.dist-info/RECORD +49 -0
- abstractruntime-0.4.0.dist-info/entry_points.txt +2 -0
- abstractruntime-0.0.1.dist-info/RECORD +0 -30
- {abstractruntime-0.0.1.dist-info → abstractruntime-0.4.0.dist-info}/WHEEL +0 -0
- {abstractruntime-0.0.1.dist-info → abstractruntime-0.4.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""RunState.vars namespacing helpers.
|
|
2
|
+
|
|
3
|
+
AbstractRuntime treats `RunState.vars` as JSON-serializable user/workflow state.
|
|
4
|
+
To avoid key collisions and to clarify ownership, we use a simple convention:
|
|
5
|
+
|
|
6
|
+
- `context`: user-facing context (task, conversation, inputs)
|
|
7
|
+
- `scratchpad`: agent/workflow working memory (iteration counters, plans)
|
|
8
|
+
- `_runtime`: runtime/host-managed metadata (tool specs, inbox, etc.)
|
|
9
|
+
- `_temp`: ephemeral step-to-step values (llm_response, tool_results, etc.)
|
|
10
|
+
- `_limits`: runtime resource limits (max_iterations, max_tokens, etc.)
|
|
11
|
+
|
|
12
|
+
This is a convention, not a strict schema; helpers here are intentionally small.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from typing import Any, Dict
|
|
18
|
+
|
|
19
|
+
CONTEXT = "context"
|
|
20
|
+
SCRATCHPAD = "scratchpad"
|
|
21
|
+
RUNTIME = "_runtime"
|
|
22
|
+
TEMP = "_temp"
|
|
23
|
+
LIMITS = "_limits" # Canonical storage for runtime resource limits
|
|
24
|
+
NODE_TRACES = "node_traces" # _runtime namespace key for per-node execution traces
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def ensure_namespaces(vars: Dict[str, Any]) -> Dict[str, Any]:
|
|
28
|
+
"""Ensure the four canonical namespaces exist and are dicts."""
|
|
29
|
+
for key in (CONTEXT, SCRATCHPAD, RUNTIME, TEMP):
|
|
30
|
+
current = vars.get(key)
|
|
31
|
+
if not isinstance(current, dict):
|
|
32
|
+
vars[key] = {}
|
|
33
|
+
return vars
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def get_namespace(vars: Dict[str, Any], key: str) -> Dict[str, Any]:
|
|
37
|
+
ensure_namespaces(vars)
|
|
38
|
+
return vars[key] # type: ignore[return-value]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def get_context(vars: Dict[str, Any]) -> Dict[str, Any]:
|
|
42
|
+
return get_namespace(vars, CONTEXT)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def get_scratchpad(vars: Dict[str, Any]) -> Dict[str, Any]:
|
|
46
|
+
return get_namespace(vars, SCRATCHPAD)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def get_runtime(vars: Dict[str, Any]) -> Dict[str, Any]:
|
|
50
|
+
return get_namespace(vars, RUNTIME)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def get_temp(vars: Dict[str, Any]) -> Dict[str, Any]:
|
|
54
|
+
return get_namespace(vars, TEMP)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def clear_temp(vars: Dict[str, Any]) -> None:
|
|
58
|
+
get_temp(vars).clear()
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def get_limits(vars: Dict[str, Any]) -> Dict[str, Any]:
|
|
62
|
+
"""Get the _limits namespace, creating with defaults if missing."""
|
|
63
|
+
if LIMITS not in vars or not isinstance(vars.get(LIMITS), dict):
|
|
64
|
+
vars[LIMITS] = _default_limits()
|
|
65
|
+
return vars[LIMITS] # type: ignore[return-value]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def ensure_limits(vars: Dict[str, Any]) -> Dict[str, Any]:
|
|
69
|
+
"""Ensure _limits namespace exists with defaults.
|
|
70
|
+
|
|
71
|
+
This is the canonical location for runtime resource limits:
|
|
72
|
+
- max_iterations / current_iteration: Iteration control
|
|
73
|
+
- max_tokens / estimated_tokens_used: Token/context window management
|
|
74
|
+
- max_history_messages: Conversation history limit (-1 = unlimited)
|
|
75
|
+
- warn_*_pct: Warning thresholds for proactive notifications
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
The _limits dict (mutable reference into vars)
|
|
79
|
+
"""
|
|
80
|
+
return get_limits(vars)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def get_node_traces(vars: Dict[str, Any]) -> Dict[str, Any]:
|
|
84
|
+
"""Return the runtime-owned per-node trace mapping.
|
|
85
|
+
|
|
86
|
+
Stored under `run.vars["_runtime"]["node_traces"]`.
|
|
87
|
+
This is intended for host UX/debugging and for exposing traces to higher layers.
|
|
88
|
+
"""
|
|
89
|
+
runtime_ns = get_runtime(vars)
|
|
90
|
+
traces = runtime_ns.get(NODE_TRACES)
|
|
91
|
+
if not isinstance(traces, dict):
|
|
92
|
+
traces = {}
|
|
93
|
+
runtime_ns[NODE_TRACES] = traces
|
|
94
|
+
return traces
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def get_node_trace(vars: Dict[str, Any], node_id: str) -> Dict[str, Any]:
|
|
98
|
+
"""Return a single node trace object (always a dict)."""
|
|
99
|
+
traces = get_node_traces(vars)
|
|
100
|
+
trace = traces.get(node_id)
|
|
101
|
+
if isinstance(trace, dict):
|
|
102
|
+
return trace
|
|
103
|
+
return {"node_id": node_id, "steps": []}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _default_limits() -> Dict[str, Any]:
|
|
107
|
+
"""Return default limits dict."""
|
|
108
|
+
return {
|
|
109
|
+
"max_iterations": 25,
|
|
110
|
+
"current_iteration": 0,
|
|
111
|
+
"max_tokens": 32768,
|
|
112
|
+
"max_output_tokens": None,
|
|
113
|
+
"max_history_messages": -1,
|
|
114
|
+
"estimated_tokens_used": 0,
|
|
115
|
+
"warn_iterations_pct": 80,
|
|
116
|
+
"warn_tokens_pct": 80,
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def parse_vars_path(path: str) -> list[Any]:
|
|
121
|
+
"""Parse a path for inspecting `RunState.vars`.
|
|
122
|
+
|
|
123
|
+
Supports:
|
|
124
|
+
- dot paths: "scratchpad.research.sources[0].title"
|
|
125
|
+
- JSON pointer-ish paths: "/scratchpad/research/sources/0/title"
|
|
126
|
+
"""
|
|
127
|
+
import re
|
|
128
|
+
|
|
129
|
+
raw = str(path or "").strip()
|
|
130
|
+
if not raw:
|
|
131
|
+
return []
|
|
132
|
+
|
|
133
|
+
tokens: list[Any] = []
|
|
134
|
+
|
|
135
|
+
if raw.startswith("/"):
|
|
136
|
+
for part in [p for p in raw.split("/") if p]:
|
|
137
|
+
part = part.replace("~1", "/").replace("~0", "~")
|
|
138
|
+
if part.isdigit():
|
|
139
|
+
tokens.append(int(part))
|
|
140
|
+
else:
|
|
141
|
+
tokens.append(part)
|
|
142
|
+
return tokens
|
|
143
|
+
|
|
144
|
+
for part in [p for p in raw.split(".") if p]:
|
|
145
|
+
# Allow list indexing as a bare segment: `foo.0.bar`
|
|
146
|
+
if "[" not in part and part.isdigit():
|
|
147
|
+
tokens.append(int(part))
|
|
148
|
+
continue
|
|
149
|
+
|
|
150
|
+
# Split `foo[0][1]` into ["foo", 0, 1]
|
|
151
|
+
for m in re.finditer(r"([^\[\]]+)|\[(\d+)\]", part):
|
|
152
|
+
key = m.group(1)
|
|
153
|
+
idx = m.group(2)
|
|
154
|
+
if key is not None:
|
|
155
|
+
tokens.append(key)
|
|
156
|
+
elif idx is not None:
|
|
157
|
+
tokens.append(int(idx))
|
|
158
|
+
|
|
159
|
+
return tokens
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def resolve_vars_path(root: Any, tokens: list[Any]) -> Any:
|
|
163
|
+
"""Resolve tokens against nested dict/list structures."""
|
|
164
|
+
cur: Any = root
|
|
165
|
+
at: list[str] = []
|
|
166
|
+
|
|
167
|
+
for tok in tokens:
|
|
168
|
+
if isinstance(tok, int):
|
|
169
|
+
if not isinstance(cur, list):
|
|
170
|
+
where = ".".join([p for p in at if p]) or "(root)"
|
|
171
|
+
raise ValueError(f"Expected list at {where} but found {type(cur).__name__}")
|
|
172
|
+
if tok < 0 or tok >= len(cur):
|
|
173
|
+
where = ".".join([p for p in at if p]) or "(root)"
|
|
174
|
+
raise ValueError(f"Index {tok} out of range at {where} (len={len(cur)})")
|
|
175
|
+
cur = cur[tok]
|
|
176
|
+
at.append(str(tok))
|
|
177
|
+
continue
|
|
178
|
+
|
|
179
|
+
key = str(tok)
|
|
180
|
+
if not isinstance(cur, dict):
|
|
181
|
+
where = ".".join([p for p in at if p]) or "(root)"
|
|
182
|
+
raise ValueError(f"Expected object at {where} but found {type(cur).__name__}")
|
|
183
|
+
if key not in cur:
|
|
184
|
+
where = ".".join([p for p in at if p]) or "(root)"
|
|
185
|
+
raise ValueError(f"Missing key '{key}' at {where}")
|
|
186
|
+
cur = cur[key]
|
|
187
|
+
at.append(key)
|
|
188
|
+
|
|
189
|
+
return cur
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
"""abstractruntime.evidence.recorder
|
|
2
|
+
|
|
3
|
+
Evidence is "provenance-first": a durable record of what the system actually observed at
|
|
4
|
+
external boundaries (web + process execution), stored as artifacts with a small JSON index
|
|
5
|
+
in run state.
|
|
6
|
+
|
|
7
|
+
Design goals:
|
|
8
|
+
- Always-on capture for a small default set of tools (web_search/fetch_url/execute_command).
|
|
9
|
+
- Keep RunState.vars JSON-safe and bounded: store large payloads in ArtifactStore and keep refs.
|
|
10
|
+
- Make later indexing/storage upgrades possible (Elastic/vector/etc) without changing semantics.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import json
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
from datetime import datetime, timezone
|
|
18
|
+
from typing import Any, Dict, List, Optional, Sequence
|
|
19
|
+
|
|
20
|
+
from ..core.models import RunState
|
|
21
|
+
from ..storage.artifacts import ArtifactStore, artifact_ref, is_artifact_ref
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
DEFAULT_EVIDENCE_TOOL_NAMES: tuple[str, ...] = ("web_search", "fetch_url", "execute_command")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def utc_now_iso() -> str:
|
|
28
|
+
return datetime.now(timezone.utc).isoformat()
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _ensure_memory_spans(run: RunState) -> list[dict[str, Any]]:
|
|
32
|
+
runtime_ns = run.vars.get("_runtime")
|
|
33
|
+
if not isinstance(runtime_ns, dict):
|
|
34
|
+
runtime_ns = {}
|
|
35
|
+
run.vars["_runtime"] = runtime_ns
|
|
36
|
+
spans = runtime_ns.get("memory_spans")
|
|
37
|
+
if not isinstance(spans, list):
|
|
38
|
+
spans = []
|
|
39
|
+
runtime_ns["memory_spans"] = spans
|
|
40
|
+
return spans
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _preview(text: str, *, limit: int = 160) -> str:
|
|
44
|
+
s = str(text or "").strip()
|
|
45
|
+
if len(s) <= limit:
|
|
46
|
+
return s
|
|
47
|
+
return s[: max(0, limit - 1)] + "…"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _json_loads_maybe(text: str) -> Optional[Any]:
|
|
51
|
+
if not isinstance(text, str):
|
|
52
|
+
return None
|
|
53
|
+
t = text.strip()
|
|
54
|
+
if not t:
|
|
55
|
+
return None
|
|
56
|
+
if not (t.startswith("{") or t.startswith("[")):
|
|
57
|
+
return None
|
|
58
|
+
try:
|
|
59
|
+
return json.loads(t)
|
|
60
|
+
except Exception:
|
|
61
|
+
return None
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _store_text(
|
|
65
|
+
store: ArtifactStore,
|
|
66
|
+
*,
|
|
67
|
+
text: str,
|
|
68
|
+
run_id: str,
|
|
69
|
+
tags: Dict[str, str],
|
|
70
|
+
content_type: str = "text/plain",
|
|
71
|
+
) -> Optional[Dict[str, str]]:
|
|
72
|
+
s = str(text or "")
|
|
73
|
+
if not s:
|
|
74
|
+
return None
|
|
75
|
+
meta = store.store_text(s, content_type=content_type, run_id=run_id, tags=tags)
|
|
76
|
+
return artifact_ref(meta.artifact_id)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _store_json(
|
|
80
|
+
store: ArtifactStore,
|
|
81
|
+
*,
|
|
82
|
+
data: Any,
|
|
83
|
+
run_id: str,
|
|
84
|
+
tags: Dict[str, str],
|
|
85
|
+
) -> Optional[Dict[str, str]]:
|
|
86
|
+
if data is None:
|
|
87
|
+
return None
|
|
88
|
+
meta = store.store_json(data, run_id=run_id, tags=tags)
|
|
89
|
+
return artifact_ref(meta.artifact_id)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@dataclass(frozen=True)
|
|
93
|
+
class EvidenceCaptureStats:
|
|
94
|
+
recorded: int = 0
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class EvidenceRecorder:
|
|
98
|
+
"""Runtime-side recorder for always-on evidence."""
|
|
99
|
+
|
|
100
|
+
def __init__(
|
|
101
|
+
self,
|
|
102
|
+
*,
|
|
103
|
+
artifact_store: ArtifactStore,
|
|
104
|
+
tool_names: Sequence[str] = DEFAULT_EVIDENCE_TOOL_NAMES,
|
|
105
|
+
):
|
|
106
|
+
self._store = artifact_store
|
|
107
|
+
self._tool_names = {str(n).strip() for n in tool_names if isinstance(n, str) and n.strip()}
|
|
108
|
+
|
|
109
|
+
def record_tool_calls(
|
|
110
|
+
self,
|
|
111
|
+
*,
|
|
112
|
+
run: RunState,
|
|
113
|
+
node_id: str,
|
|
114
|
+
tool_calls: list[Any],
|
|
115
|
+
tool_results: Dict[str, Any],
|
|
116
|
+
) -> EvidenceCaptureStats:
|
|
117
|
+
if not isinstance(tool_results, dict):
|
|
118
|
+
return EvidenceCaptureStats(recorded=0)
|
|
119
|
+
results = tool_results.get("results", [])
|
|
120
|
+
if not isinstance(results, list) or not results:
|
|
121
|
+
return EvidenceCaptureStats(recorded=0)
|
|
122
|
+
if not isinstance(tool_calls, list):
|
|
123
|
+
tool_calls = []
|
|
124
|
+
|
|
125
|
+
spans = _ensure_memory_spans(run)
|
|
126
|
+
recorded = 0
|
|
127
|
+
|
|
128
|
+
for idx, r in enumerate(results):
|
|
129
|
+
if not isinstance(r, dict):
|
|
130
|
+
continue
|
|
131
|
+
call = tool_calls[idx] if idx < len(tool_calls) and isinstance(tool_calls[idx], dict) else {}
|
|
132
|
+
tool_name = str(r.get("name") or call.get("name") or "").strip()
|
|
133
|
+
if not tool_name or tool_name not in self._tool_names:
|
|
134
|
+
continue
|
|
135
|
+
|
|
136
|
+
ok = bool(r.get("success") is True)
|
|
137
|
+
call_id = str(r.get("call_id") or call.get("call_id") or "")
|
|
138
|
+
error = r.get("error")
|
|
139
|
+
error_text = str(error).strip() if isinstance(error, str) and error.strip() else None
|
|
140
|
+
args = call.get("arguments") if isinstance(call, dict) else None
|
|
141
|
+
args_dict = dict(args) if isinstance(args, dict) else {}
|
|
142
|
+
|
|
143
|
+
output = r.get("output")
|
|
144
|
+
# Tool executors vary: output may be str/dict/None.
|
|
145
|
+
output_dict = dict(output) if isinstance(output, dict) else None
|
|
146
|
+
output_text = str(output or "") if isinstance(output, str) else None
|
|
147
|
+
|
|
148
|
+
created_at = utc_now_iso()
|
|
149
|
+
tags: Dict[str, str] = {"kind": "evidence", "tool": tool_name}
|
|
150
|
+
|
|
151
|
+
evidence_payload: Dict[str, Any] = {
|
|
152
|
+
"tool_name": tool_name,
|
|
153
|
+
"call_id": call_id,
|
|
154
|
+
"success": ok,
|
|
155
|
+
"error": error_text,
|
|
156
|
+
"created_at": created_at,
|
|
157
|
+
"run_id": run.run_id,
|
|
158
|
+
"workflow_id": run.workflow_id,
|
|
159
|
+
"node_id": node_id,
|
|
160
|
+
"arguments": args_dict,
|
|
161
|
+
}
|
|
162
|
+
if run.actor_id:
|
|
163
|
+
evidence_payload["actor_id"] = str(run.actor_id)
|
|
164
|
+
if getattr(run, "session_id", None):
|
|
165
|
+
evidence_payload["session_id"] = str(run.session_id)
|
|
166
|
+
|
|
167
|
+
artifacts: Dict[str, Any] = {}
|
|
168
|
+
|
|
169
|
+
if tool_name == "fetch_url":
|
|
170
|
+
url = str(args_dict.get("url") or "")
|
|
171
|
+
if url:
|
|
172
|
+
tags["url"] = url[:200]
|
|
173
|
+
|
|
174
|
+
if isinstance(output_dict, dict):
|
|
175
|
+
# Store and strip large text fields from the tool output dict.
|
|
176
|
+
raw_text = output_dict.pop("raw_text", None)
|
|
177
|
+
norm_text = output_dict.pop("normalized_text", None)
|
|
178
|
+
content_type = output_dict.get("content_type")
|
|
179
|
+
content_type_str = str(content_type) if isinstance(content_type, str) else ""
|
|
180
|
+
|
|
181
|
+
raw_ref = None
|
|
182
|
+
if isinstance(raw_text, str) and raw_text:
|
|
183
|
+
raw_ref = _store_text(
|
|
184
|
+
self._store,
|
|
185
|
+
text=raw_text,
|
|
186
|
+
run_id=run.run_id,
|
|
187
|
+
tags={**tags, "part": "raw"},
|
|
188
|
+
content_type=content_type_str or "text/plain",
|
|
189
|
+
)
|
|
190
|
+
output_dict["raw_artifact"] = raw_ref
|
|
191
|
+
artifacts["raw"] = raw_ref
|
|
192
|
+
|
|
193
|
+
norm_ref = None
|
|
194
|
+
if isinstance(norm_text, str) and norm_text:
|
|
195
|
+
norm_ref = _store_text(
|
|
196
|
+
self._store,
|
|
197
|
+
text=norm_text,
|
|
198
|
+
run_id=run.run_id,
|
|
199
|
+
tags={**tags, "part": "normalized"},
|
|
200
|
+
content_type="text/plain",
|
|
201
|
+
)
|
|
202
|
+
output_dict["normalized_artifact"] = norm_ref
|
|
203
|
+
artifacts["normalized_text"] = norm_ref
|
|
204
|
+
|
|
205
|
+
evidence_payload["url"] = str(output_dict.get("url") or url)
|
|
206
|
+
evidence_payload["final_url"] = str(output_dict.get("final_url") or "")
|
|
207
|
+
evidence_payload["content_type"] = content_type_str
|
|
208
|
+
evidence_payload["size_bytes"] = output_dict.get("size_bytes")
|
|
209
|
+
if artifacts:
|
|
210
|
+
evidence_payload["artifacts"] = artifacts
|
|
211
|
+
|
|
212
|
+
# Write back the stripped/augmented dict into the tool result so run state stays small.
|
|
213
|
+
r["output"] = output_dict
|
|
214
|
+
|
|
215
|
+
elif tool_name == "execute_command":
|
|
216
|
+
cmd = str(args_dict.get("command") or "")
|
|
217
|
+
if cmd:
|
|
218
|
+
tags["command"] = _preview(cmd, limit=200)
|
|
219
|
+
|
|
220
|
+
if isinstance(output_dict, dict):
|
|
221
|
+
stdout = output_dict.pop("stdout", None)
|
|
222
|
+
stderr = output_dict.pop("stderr", None)
|
|
223
|
+
|
|
224
|
+
stdout_ref = None
|
|
225
|
+
if isinstance(stdout, str) and stdout:
|
|
226
|
+
stdout_ref = _store_text(
|
|
227
|
+
self._store,
|
|
228
|
+
text=stdout,
|
|
229
|
+
run_id=run.run_id,
|
|
230
|
+
tags={**tags, "part": "stdout"},
|
|
231
|
+
)
|
|
232
|
+
output_dict["stdout_artifact"] = stdout_ref
|
|
233
|
+
artifacts["stdout"] = stdout_ref
|
|
234
|
+
|
|
235
|
+
stderr_ref = None
|
|
236
|
+
if isinstance(stderr, str) and stderr:
|
|
237
|
+
stderr_ref = _store_text(
|
|
238
|
+
self._store,
|
|
239
|
+
text=stderr,
|
|
240
|
+
run_id=run.run_id,
|
|
241
|
+
tags={**tags, "part": "stderr"},
|
|
242
|
+
)
|
|
243
|
+
output_dict["stderr_artifact"] = stderr_ref
|
|
244
|
+
artifacts["stderr"] = stderr_ref
|
|
245
|
+
|
|
246
|
+
evidence_payload["command"] = str(output_dict.get("command") or cmd)
|
|
247
|
+
evidence_payload["return_code"] = output_dict.get("return_code")
|
|
248
|
+
evidence_payload["duration_s"] = output_dict.get("duration_s")
|
|
249
|
+
evidence_payload["working_directory"] = output_dict.get("working_directory")
|
|
250
|
+
evidence_payload["platform"] = output_dict.get("platform")
|
|
251
|
+
if artifacts:
|
|
252
|
+
evidence_payload["artifacts"] = artifacts
|
|
253
|
+
|
|
254
|
+
r["output"] = output_dict
|
|
255
|
+
|
|
256
|
+
elif isinstance(output_text, str) and output_text:
|
|
257
|
+
out_ref = _store_text(
|
|
258
|
+
self._store,
|
|
259
|
+
text=output_text,
|
|
260
|
+
run_id=run.run_id,
|
|
261
|
+
tags={**tags, "part": "output"},
|
|
262
|
+
)
|
|
263
|
+
if out_ref is not None:
|
|
264
|
+
artifacts["output"] = out_ref
|
|
265
|
+
evidence_payload["artifacts"] = artifacts
|
|
266
|
+
|
|
267
|
+
elif tool_name == "web_search":
|
|
268
|
+
query = str(args_dict.get("query") or "")
|
|
269
|
+
if query:
|
|
270
|
+
tags["query"] = _preview(query, limit=200)
|
|
271
|
+
evidence_payload["query"] = query
|
|
272
|
+
|
|
273
|
+
if isinstance(output_text, str) and output_text:
|
|
274
|
+
parsed = _json_loads_maybe(output_text)
|
|
275
|
+
if parsed is not None:
|
|
276
|
+
out_ref = _store_json(self._store, data=parsed, run_id=run.run_id, tags={**tags, "part": "results"})
|
|
277
|
+
else:
|
|
278
|
+
out_ref = _store_text(self._store, text=output_text, run_id=run.run_id, tags={**tags, "part": "results"})
|
|
279
|
+
if out_ref is not None:
|
|
280
|
+
artifacts["results"] = out_ref
|
|
281
|
+
evidence_payload["artifacts"] = artifacts
|
|
282
|
+
elif isinstance(output_dict, dict):
|
|
283
|
+
out_ref = _store_json(self._store, data=output_dict, run_id=run.run_id, tags={**tags, "part": "results"})
|
|
284
|
+
if out_ref is not None:
|
|
285
|
+
artifacts["results"] = out_ref
|
|
286
|
+
evidence_payload["artifacts"] = artifacts
|
|
287
|
+
|
|
288
|
+
# Store the evidence record itself (small JSON with artifact refs).
|
|
289
|
+
record_ref = _store_json(self._store, data=evidence_payload, run_id=run.run_id, tags=tags)
|
|
290
|
+
if not (isinstance(record_ref, dict) and is_artifact_ref(record_ref)):
|
|
291
|
+
continue
|
|
292
|
+
evidence_id = record_ref["$artifact"]
|
|
293
|
+
|
|
294
|
+
# Append to span-like index for fast listing.
|
|
295
|
+
span_record: Dict[str, Any] = {
|
|
296
|
+
"kind": "evidence",
|
|
297
|
+
"artifact_id": evidence_id,
|
|
298
|
+
"created_at": created_at,
|
|
299
|
+
"from_timestamp": created_at,
|
|
300
|
+
"to_timestamp": created_at,
|
|
301
|
+
"message_count": 0,
|
|
302
|
+
"tool_name": tool_name,
|
|
303
|
+
"call_id": call_id,
|
|
304
|
+
"success": ok,
|
|
305
|
+
}
|
|
306
|
+
if tool_name == "fetch_url":
|
|
307
|
+
span_record["url"] = evidence_payload.get("url") or str(args_dict.get("url") or "")
|
|
308
|
+
elif tool_name == "web_search":
|
|
309
|
+
span_record["query"] = str(args_dict.get("query") or "")
|
|
310
|
+
elif tool_name == "execute_command":
|
|
311
|
+
span_record["command_preview"] = _preview(str(args_dict.get("command") or ""))
|
|
312
|
+
|
|
313
|
+
# Attach span id back to the tool result entry for easy linking in traces/UIs.
|
|
314
|
+
meta = r.get("meta")
|
|
315
|
+
if not isinstance(meta, dict):
|
|
316
|
+
meta = {}
|
|
317
|
+
r["meta"] = meta
|
|
318
|
+
meta["evidence_id"] = evidence_id
|
|
319
|
+
|
|
320
|
+
spans.append(span_record)
|
|
321
|
+
recorded += 1
|
|
322
|
+
|
|
323
|
+
return EvidenceCaptureStats(recorded=recorded)
|
|
324
|
+
|
|
325
|
+
|
|
@@ -7,16 +7,18 @@ Provides:
|
|
|
7
7
|
- Tool executors (executed + passthrough)
|
|
8
8
|
- Effect handlers wiring
|
|
9
9
|
- Convenience runtime factories for local/remote/hybrid modes
|
|
10
|
+
- RuntimeConfig for limits and model capabilities
|
|
10
11
|
|
|
11
12
|
Importing this module is the explicit opt-in to an AbstractCore dependency.
|
|
12
13
|
"""
|
|
13
14
|
|
|
15
|
+
from ...core.config import RuntimeConfig
|
|
14
16
|
from .llm_client import (
|
|
15
17
|
AbstractCoreLLMClient,
|
|
16
18
|
LocalAbstractCoreLLMClient,
|
|
17
19
|
RemoteAbstractCoreLLMClient,
|
|
18
20
|
)
|
|
19
|
-
from .tool_executor import AbstractCoreToolExecutor, PassthroughToolExecutor, ToolExecutor
|
|
21
|
+
from .tool_executor import AbstractCoreToolExecutor, MappingToolExecutor, PassthroughToolExecutor, ToolExecutor
|
|
20
22
|
from .effect_handlers import build_effect_handlers
|
|
21
23
|
from .factory import (
|
|
22
24
|
create_hybrid_runtime,
|
|
@@ -25,19 +27,24 @@ from .factory import (
|
|
|
25
27
|
create_remote_file_runtime,
|
|
26
28
|
create_remote_runtime,
|
|
27
29
|
)
|
|
30
|
+
from .observability import attach_global_event_bus_bridge, emit_step_record
|
|
28
31
|
|
|
29
32
|
__all__ = [
|
|
30
33
|
"AbstractCoreLLMClient",
|
|
31
34
|
"LocalAbstractCoreLLMClient",
|
|
32
35
|
"RemoteAbstractCoreLLMClient",
|
|
36
|
+
"RuntimeConfig",
|
|
33
37
|
"ToolExecutor",
|
|
38
|
+
"MappingToolExecutor",
|
|
34
39
|
"AbstractCoreToolExecutor",
|
|
35
40
|
"PassthroughToolExecutor",
|
|
41
|
+
|
|
36
42
|
"build_effect_handlers",
|
|
37
43
|
"create_local_runtime",
|
|
38
44
|
"create_remote_runtime",
|
|
39
45
|
"create_hybrid_runtime",
|
|
40
46
|
"create_local_file_runtime",
|
|
41
47
|
"create_remote_file_runtime",
|
|
48
|
+
"attach_global_event_bus_bridge",
|
|
49
|
+
"emit_step_record",
|
|
42
50
|
]
|
|
43
|
-
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""abstractruntime.integrations.abstractcore.constants
|
|
2
|
+
|
|
3
|
+
Single source of truth for AbstractRuntime orchestration defaults when it
|
|
4
|
+
executes AbstractCore-backed effects (LLM calls and tool calls).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
# Default *effect* timeouts (seconds).
|
|
8
|
+
#
|
|
9
|
+
# IMPORTANT: These are NOT a "workflow/run TTL". Workflows can be long-lived
|
|
10
|
+
# (hours/days) or even continuous. These limits only apply to a *single*
|
|
11
|
+
# runtime-managed operation (e.g. one LLM HTTP request, one tool call).
|
|
12
|
+
#
|
|
13
|
+
# Rationale:
|
|
14
|
+
# - Local inference can be slow for large contexts.
|
|
15
|
+
# - In an orchestrator, timeouts are policy and should be explicit + consistent.
|
|
16
|
+
DEFAULT_LLM_TIMEOUT_S: float = 7200.0
|
|
17
|
+
DEFAULT_TOOL_TIMEOUT_S: float = 7200.0
|
|
18
|
+
|
|
19
|
+
|