Skip to content

ToolSet Node

graphorchestrator.nodes.nodes.ToolSetNode

Bases: ProcessingNode

A ProcessingNode that invokes a remote ToolSetServer endpoint as an HTTP call.

Each execution: 1. Sends the current State.messages as JSON to {base_url}/tools/{tool_name}. 2. Parses the JSON response into a new State.

Source code in graphorchestrator\nodes\nodes.py
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
class ToolSetNode(ProcessingNode):
    """
    A ProcessingNode that invokes a remote ToolSetServer endpoint as an HTTP call.

    Each execution:
    1. Sends the current State.messages as JSON to `{base_url}/tools/{tool_name}`.
    2. Parses the JSON response into a new State.
    """

    httpx = httpx

    def __init__(self, node_id: str, base_url: str, tool_name: str) -> None:
        self.base_url = base_url.rstrip("/")
        self.tool_name = tool_name
        action = self._make_tool_action()

        GraphLogger.get().info(
            **wrap_constants(
                message="ToolSetNode initialized",
                **{
                    LC.EVENT_TYPE: "tool",
                    LC.NODE_ID: node_id,
                    LC.NODE_TYPE: "ToolSetNode",
                    LC.ACTION: "node_created",
                    LC.CUSTOM: {"tool_name": self.tool_name, "base_url": self.base_url},
                },
            )
        )

        super().__init__(node_id, action)

    def _make_tool_action(self) -> Callable[[State], State]:
        """
        Constructs the @node_action-wrapped coroutine that performs the HTTP call.
        """
        url = f"{self.base_url}/tools/{self.tool_name}"

        @node_action
        async def _action(state: State) -> State:
            log = GraphLogger.get()

            log.info(
                **wrap_constants(
                    message="ToolSetNode HTTP request started",
                    **{
                        LC.EVENT_TYPE: "tool",
                        LC.NODE_ID: self.node_id,
                        LC.NODE_TYPE: "ToolSetNode",
                        LC.ACTION: "tool_http_start",
                        LC.INPUT_SIZE: len(state.messages),
                        LC.CUSTOM: {"url": url},
                    },
                )
            )

            payload = {"messages": state.messages}
            async with httpx.AsyncClient() as client:
                resp = await client.post(url, json=payload, timeout=10.0)
                resp.raise_for_status()
                data = resp.json()
                new_state = State(messages=data.get("messages", []))

                log.info(
                    **wrap_constants(
                        message="ToolSetNode HTTP call succeeded",
                        **{
                            LC.EVENT_TYPE: "tool",
                            LC.NODE_ID: self.node_id,
                            LC.NODE_TYPE: "ToolSetNode",
                            LC.ACTION: "tool_http_success",
                            LC.OUTPUT_SIZE: len(new_state.messages),
                            LC.SUCCESS: True,
                            LC.CUSTOM: {"url": url, "status_code": resp.status_code},
                        },
                    )
                )

                return new_state

        return _action