Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/narada-core/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "narada-core"
version = "0.0.23"
version = "0.0.24"
description = "Code shared by the `narada` and `narada-pyodide` packages."
license = "Apache-2.0"
readme = "README.md"
Expand Down
2 changes: 2 additions & 0 deletions packages/narada-core/src/narada_core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ class RunCustomAgentTrace(TypedDict):
workflow_name: str
status: Literal["success", "error"]
error_message: NotRequired[str]
children: NotRequired[ActionTrace]


class IfTrace(TypedDict):
Expand Down Expand Up @@ -312,6 +313,7 @@ class PythonSubAgentCallEvent(TypedDict):
prompt: str
status: Literal["success", "error", "timeout"]
request_id: NotRequired[str]
text: NotRequired[str]
error_message: NotRequired[str]
action_trace: NotRequired[ActionTrace]

Expand Down
2 changes: 2 additions & 0 deletions packages/narada-core/src/narada_core/tracing/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class RunCustomAgentTrace(BaseModel):
workflow_name: str
status: Literal["success", "error"]
error_message: str | None = None
children: ActionTrace | None = None


class IfTrace(BaseModel):
Expand Down Expand Up @@ -260,6 +261,7 @@ class PythonSubAgentCallEvent(BaseModel):
prompt: str
status: Literal["success", "error", "timeout"]
request_id: str | None = None
text: str | None = None
error_message: str | None = None
action_trace: ActionTrace | None = None

Expand Down
4 changes: 2 additions & 2 deletions packages/narada-pyodide/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

[project]
name = "narada-pyodide"
version = "0.0.52"
version = "0.0.53"
description = "Pyodide-compatible Python client SDK for Narada"
license = "Apache-2.0"
readme = "README.md"
authors = [{ name = "Narada", email = "support@narada.ai" }]
requires-python = ">=3.12"
dependencies = [
"narada-core==0.0.23",
"narada-core==0.0.24",
# Must be a supported version in https://pyodide.org/en/stable/usage/packages-in-pyodide.html
"packaging==24.2",
]
Expand Down
3 changes: 3 additions & 0 deletions packages/narada-pyodide/src/narada/_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def emit_sub_agent_call(
prompt: str,
status: SubAgentCallStatus,
request_id: str | None = None,
text: str | None = None,
error_message: str | None = None,
action_trace_raw: list[dict[str, Any]] | None = None,
) -> None:
Expand All @@ -100,6 +101,8 @@ def emit_sub_agent_call(
}
if request_id is not None:
event["request_id"] = request_id
if text is not None:
event["text"] = text
if error_message is not None:
event["error_message"] = error_message
if action_trace_raw is not None:
Expand Down
7 changes: 7 additions & 0 deletions packages/narada-pyodide/src/narada/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,19 @@ async def dispatch_request(
and response_content is not None
else None
)
trace_text: str | None = (
response_content.get("text")
if response["status"] == "success"
and response_content is not None
else None
)
_trace.emit_sub_agent_call(
ts_start=trace_start_ms,
agent_type=agent_type_str,
prompt=prompt,
status=trace_status,
request_id=request_id,
text=trace_text,
error_message=trace_error,
action_trace_raw=(
response_content.get("actionTrace")
Expand Down
80 changes: 80 additions & 0 deletions packages/narada-pyodide/tests/test_cloud_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,86 @@ async def test_dispatch_request_emits_string_trace_agent_type_for_sdk_enum(
assert json.loads(emitted_events[0])["agent_type"] == "operator"


@pytest.mark.asyncio
async def test_dispatch_request_emits_success_text_in_sub_agent_trace(
monkeypatch: pytest.MonkeyPatch,
) -> None:
pyfetch = AsyncMock(
side_effect=[
_FakeResponse(json_data={"requestId": "req-123"}),
_FakeResponse(
json_data={
"status": "success",
"response": {
"text": "TRACE_CORE_AGENT_DONE",
"actionTrace": [],
},
}
),
]
)
narada_pkg, _, window_module = _import_pyodide_narada(monkeypatch, pyfetch=pyfetch)
emitted_events: list[str] = []
monkeypatch.setattr(
sys.modules["narada._trace"],
"_narada_emit_trace_event",
emitted_events.append,
raising=False,
)

window = window_module.CloudBrowserWindow(
browser_window_id="browser-window-123",
session_id="session-123",
api_key="test-api-key",
)
response = await window.dispatch_request(
prompt="reply with marker",
agent=narada_pkg.Agent.CORE_AGENT,
)

from narada_core.tracing.model import PythonSubAgentCallEvent

assert response["status"] == "success"
assert len(emitted_events) == 1
event = json.loads(emitted_events[0])
parsed_event = PythonSubAgentCallEvent.model_validate(event)
assert parsed_event.agent_type == "coreAgent"
assert parsed_event.text == "TRACE_CORE_AGENT_DONE"
assert parsed_event.action_trace == []


def test_parse_action_trace_preserves_run_custom_agent_children(
monkeypatch: pytest.MonkeyPatch,
) -> None:
monkeypatch.syspath_prepend(str(CORE_SRC))

from narada_core.tracing.model import parse_action_trace

parsed_trace = parse_action_trace(
[
{
"step_type": "runCustomAgent",
"url": "https://example.com",
"workflow_id": "workflow-parent",
"workflow_name": "Parent workflow",
"status": "success",
"children": [
{
"step_type": "print",
"url": "https://example.com",
"message": "TRACE_GUI_CHILD_DONE",
}
],
}
]
)

assert parsed_trace[0].step_type == "runCustomAgent"
assert parsed_trace[0].children is not None
assert parsed_trace[0].children[0].step_type == "print"
assert parsed_trace[0].children[0].message == "TRACE_GUI_CHILD_DONE"


@pytest.mark.asyncio
async def test_cloud_browser_window_dispatch_request_preserves_current_file_variable_shape(
monkeypatch: pytest.MonkeyPatch,
Expand Down
4 changes: 2 additions & 2 deletions packages/narada/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[project]
name = "narada"
version = "0.1.53a2"
version = "0.1.53a3"
description = "Python client SDK for Narada"
license = "Apache-2.0"
readme = "README.md"
authors = [{ name = "Narada", email = "support@narada.ai" }]
requires-python = ">=3.12"
dependencies = [
"narada-core==0.0.23",
"narada-core==0.0.24",
"aiohttp>=3.12.13",
"playwright>=1.53.0",
"rich>=14.0.0",
Expand Down
6 changes: 3 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading