Table of Contents

Method WithDefinition

Namespace
LMKit.Agents
Assembly
LM-Kit.NET.dll

WithDefinition(AgentDefinition, Func<string, ITool>, Func<string, AgentSkill>, AgentMemory, Func<IReadOnlyList<string>, IKnowledgeRetriever>)

Configures the agent from a portable AgentDefinition, resolved exactly as an LM-Kit server resolves it (ApplyTo(AgentInvocation)): its prompt, its pinned skill's instructions, its tools, its tool-call budget, its memory, its knowledge, its output schema and, when it simulates tools, the simulation of every tool that writes.

public AgentBuilder WithDefinition(AgentDefinition definition, Func<string, ITool> resolveTool = null, Func<string, AgentSkill> resolveSkill = null, AgentMemory memory = null, Func<IReadOnlyList<string>, IKnowledgeRetriever> resolveKnowledge = null)

Parameters

definition AgentDefinition

The definition to run.

resolveTool Func<string, ITool>

Binds a tool name to a tool instance. null, or a null answer, falls back to the built-in tool of that name (GetAll()).

resolveSkill Func<string, AgentSkill>

Binds the pinned skill's name to a skill; null when the host has no skills.

memory AgentMemory

The memory a remembering definition uses; null runs without memory.

resolveKnowledge Func<IReadOnlyList<string>, IKnowledgeRetriever>

Binds the definition's knowledge source references (Knowledge) to a retriever; required when the definition names sources.

Returns

AgentBuilder

This builder instance for method chaining.

Examples

var definition = AgentDefinition.FromJson(File.ReadAllText("support.agent.json"));

var agent = Agent.CreateBuilder(model)
    .WithDefinition(definition, resolveSkill: name => skills.Get(name), memory: memory)
    .Build();

Remarks

A tool, skill or knowledge source the definition names that the host cannot bind fails here, with its name, rather than mid-conversation. The model and the thinking level stay the host's: pass the model to CreateBuilder(LM) and the level through ReasoningLevel.

Exceptions

ArgumentNullException

Thrown when definition is null.

InvalidOperationException

Thrown when a tool or the pinned skill cannot be bound.

Share