Skip to main content
The LLM template demonstrates how to make a simple call to an LLM using the LLM primitive.

Run the Template

  1. Go to Assets/InworldRuntime/Scenes/Primitives and play the LLMTemplate Scene.
  2. Switch LLM models, configure the parameters, then press the Connect button.
  3. Type messages to the agent.
The agent remembers the chat history within the current conversation. LLM01
  1. You can also switch to local models by toggling the Remote button.
By default it uses StreamingAssets/llm/Meta-Llama-3.1-8B-Instruct-Q8_0.gguf, but you can also use your own models.
If you’re using the Local models, we recommend setting the Device to CUDA for better performance.
LLM02

Understanding the Template

Structure

  • This demo has a single prefab under InworldController, LLM, which contains InworldLLMModule.
  • When InworldController initializes, it calls InworldLLMModule.InitializeAsync() (see Primitives Overview).
  • This function creates an LLMFactory, then creates an LLMInterface based on the current LLMConfig.
LLM03

Parameters

  • Max Tokens: Maximum number of tokens to generate. Longer outputs may cost more and are truncated at this limit.
  • Max Prompt Length: Maximum tokens allowed in the prompt. Total context window = input + output, so available output ≈ window − input.
  • Temperature: Controls randomness/creativity. Lower = more deterministic; higher = more diverse.
  • Top P: Nucleus sampling. Samples only from tokens within cumulative probability P. Usually tune this or Temperature, not both.
  • Repetition Penalty: Down-weights previously generated tokens to reduce loops and verbosity.
  • Frequency Penalty: Penalizes tokens the more frequently they appear to curb repetition.
  • Presence Penalty: Penalizes tokens after their first appearance to encourage introducing new topics.

Workflow

At runtime, when InworldController invokes OnFrameworkInitialized, the demo’s LLMChatPanel listens to this event and enables the previously disabled UI. When the user presses Enter or clicks SEND, LLMChatPanel first builds the chat history and inserts it into the prompt.

Prompt

This example uses the prompt asset at Assets/InworldRuntime/Data/BasicLLM.asset. LLM04
Simple Dialogue Prompt Template
Both the user’s messages and the agent’s replies are stored in the prompt’s Conversation list (List<Utterance>). When InworldController.LLM.GenerateTextAsync() is invoked, the prompt is rendered via Jinja into the following format:
Simple Dialogue Prompt Template