Skip to main content
The node-llm-chat template illustrates how to make LLM calls using the LLM node with support for streaming, tool calling, and multimodal inputs.
Architecture
  • Backend: Inworld Agent Runtime
  • Frontend: N/A (CLI example)

Prerequisites

Run the Template

  1. Clone the templates repository:
  2. Install the Runtime SDK inside the cli directory.
  3. Set up your Base64 Runtime API key by copying the .env-sample file into a .env file in the cli folder and adding your API key.
    .env
  4. Run a basic example of calling the LLM with a text prompt:
  5. Now try changing the model and requiring JSON outputs. See Models > Chat Completion for models supported.
  6. Now let’s try with tool calling.
  7. Now let’s try with image inputs:
  8. Finally, check out your captured traces in Portal!

Understanding the Template

The main functionality of the template is contained in the run function, which demonstrates how to use the Inworld Agent Runtime to generate text using the LLM node. Let’s break it down into more detail:

1) Initialize LLM node

First, we initialize the LLM node
When creating the node, you can specify:
  • provider: The LLM service provider (inworld, openai, etc.) as specified here
  • modelName: Any model from Chat Completion
  • stream: Whether to enable streaming responses
  • textGenerationConfig: LLM generation parameters. You can learn more about these configurations here.
For convenience, createRemoteLLMChatNode does not require registering the component explicitly, before use in the node, but you can also register the component and reference it when creating the node as shown in the node_llm_chat_explicit_components.ts example. This allows you to reuse the same component across multiple nodes (for example, if you want to make multiple LLM calls with the same model).

2) Graph initialization

Next we create a new graph and add the LLM node, setting it as the start and end node. In more complex applications, you could connect multiple LLM nodes to create a processing pipeline.
The GraphBuilder configuration includes:
  • id: A unique identifier for the graph
  • enableRemoteConfig: Whether to enable remote configuration (set to false for local execution)
  • apiKey: Your Inworld API key

3) Graph input preparation

Now we create the message to send to the LLM based on the user’s input.
Below is an example of what different inputs might look like:

4) Graph execution

Execute the graph with the prepared input:

5) Response handling

Handle responses, including streaming responses.