MCPcopy Create free account
hub / github.com/NVIDIA/NeMo-Relay / tool_call_execute

Function tool_call_execute

crates/python/src/py_api/mod.rs:491–532  ·  view source on GitHub ↗
(
    py: Python<'py>,
    name: String,
    args: &Bound<'py, PyAny>,
    func: Py<PyAny>,
    handle: Option<PyScopeHandle>,
    attributes: Option<PyToolAttributes>,
    data: Option<&Bound<'py, Py

Source from the content-addressed store, hash-verified

489) -> "object", text_signature = "(name: str, args: object, func: object, *, handle: ScopeHandle | None = None, attributes: ToolAttributes | None = None, data: object | None = None, metadata: object | None = None) -> object")]
490#[allow(clippy::too_many_arguments)]
491fn tool_call_execute<'py>(
492 py: Python<'py>,
493 name: String,
494 args: &Bound<'py, PyAny>,
495 func: Py<PyAny>,
496 handle: Option<PyScopeHandle>,
497 attributes: Option<PyToolAttributes>,
498 data: Option<&Bound<'py, PyAny>>,
499 metadata: Option<&Bound<'py, PyAny>>,
500) -> PyResult<Bound<'py, PyAny>> {
501 let args_json = py_to_json(args)?;
502 let attrs = attributes
503 .map(|a| a.inner)
504 .unwrap_or(ToolAttributes::empty());
505 let data_json = opt_py_to_json(data)?;
506 let metadata_json = opt_py_to_json(metadata)?;
507 let exec_fn = py_callable::wrap_py_tool_exec_fn(func);
508 let default_fn: ToolExecutionNextFn = Arc::new(move |args| exec_fn(args));
509 let parent_handle = handle.map(|h| h.inner).unwrap_or_else(task_scope_top);
510
511 let scope_stack = current_scope_stack_handle();
512 pyo3_async_runtimes::tokio::future_into_py(py, async move {
513 TASK_SCOPE_STACK
514 .scope(scope_stack, async move {
515 let result = core_tool_api::tool_call_execute(
516 core_tool_api::ToolCallExecuteParams::builder()
517 .name(name)
518 .args(args_json)
519 .func(default_fn)
520 .parent(parent_handle)
521 .attributes(attrs)
522 .data_opt(data_json)
523 .metadata_opt(metadata_json)
524 .build(),
525 )
526 .await
527 .map_err(to_py_err)?;
528 Python::attach(|py| json_to_py(py, &result))
529 })
530 .await
531 })
532}
533
534// ---------------------------------------------------------------------------
535// LLM lifecycle

Callers

nothing calls this directly

Calls 8

py_to_jsonFunction · 0.85
opt_py_to_jsonFunction · 0.85
wrap_py_tool_exec_fnFunction · 0.85
json_to_pyFunction · 0.85
buildMethod · 0.45
attributesMethod · 0.45
funcMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected