Method WithDefinition
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
definitionAgentDefinitionThe definition to run.
resolveToolFunc<string, ITool>Binds a tool name to a tool instance.
null, or anullanswer, falls back to the built-in tool of that name (GetAll()).resolveSkillFunc<string, AgentSkill>Binds the pinned skill's name to a skill;
nullwhen the host has no skills.memoryAgentMemoryThe memory a remembering definition uses;
nullruns without memory.resolveKnowledgeFunc<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
definitionis null.- InvalidOperationException
Thrown when a tool or the pinned skill cannot be bound.