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
20 changes: 13 additions & 7 deletions agents/nemo-studio-copilot/src/nemo_studio_copilot/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
from nat.cli.register_workflow import register_function
from nat.data_models.api_server import ChatRequest, ChatResponse, ChatResponseChunk, Usage
from nat.data_models.function import FunctionBaseConfig
from nat.plugins.langchain.callback_handler import LangchainProfilerHandler
from nemo_studio_copilot.register import create_nemo_studio_copilot
from pydantic import BaseModel, ConfigDict, Field, computed_field, model_validator

Expand Down Expand Up @@ -243,13 +244,18 @@ def _build_state(value: NemoStudioCopilotWrapperInput) -> dict[str, Any]:

@staticmethod
def _invocation_config(value: NemoStudioCopilotWrapperInput) -> RunnableConfig:
if value.studio_session_id is None:
return {}
return {
"configurable": {
"studio_session_id": str(value.studio_session_id),
}
}
config: RunnableConfig = {}
# Attach NAT's LangChain profiler so tool/LLM calls emit IntermediateSteps,
# which NAT surfaces as ``intermediate_data:`` stream events (and telemetry).
# Construction binds to the request-scoped step manager; guard so calls
# outside a NAT context (e.g. unit tests) degrade gracefully.
try:
config["callbacks"] = [LangchainProfilerHandler()]
except Exception:
logger.debug("LangchainProfilerHandler unavailable; tool-call trace disabled", exc_info=True)
if value.studio_session_id is not None:
config["configurable"] = {"studio_session_id": str(value.studio_session_id)}
return config

@staticmethod
def _has_tool_calls(message: AIMessage | dict[str, Any]) -> bool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,10 @@ def test_chat_request_converts_trusted_session_to_invocation_config(self):

value = NemoStudioCopilotWrapperFunction.convert_chat_request(request)

assert NemoStudioCopilotWrapperFunction._invocation_config(value) == TRUSTED_CONFIG
# ``callbacks`` may also carry the NAT profiler handler; assert the
# session config specifically rather than the whole dict.
config = NemoStudioCopilotWrapperFunction._invocation_config(value)
assert config["configurable"] == TRUSTED_CONFIG["configurable"]

@pytest.mark.asyncio
async def test_wrapper_passes_trusted_session_config_to_graph(self):
Expand All @@ -907,7 +910,8 @@ async def test_wrapper_passes_trusted_session_config_to_graph(self):
result = await wrapper._ainvoke(value)

assert result.value == "done"
assert graph.configs == [TRUSTED_CONFIG]
assert len(graph.configs) == 1
assert graph.configs[0]["configurable"] == TRUSTED_CONFIG["configurable"]

@pytest.mark.parametrize(
"message",
Expand Down
Loading
Loading