Skip to main content

@fluidframework/tree-agent Package

A library for creating AI agents to interact with a https://fluidframework.com/docs/data-structures/tree/.

Interfaces

InterfaceAlertsDescription
ContextAlphaThe context object available to generated code when editing a tree.
EditResultAlphaA result from an edit attempt via the edit(js) function.
ExecuteSemanticEditingOptionsAlphaOptions for executeSemanticEditing(model, tree, prompt, options).
ExposedMethodsAlphaAn interface for exposing methods of schema classes to an agent.
ExposedPropertiesAlphaAn interface for exposing properties of schema classes to an agent.
FunctionDefAlphaA function definition interface that describes the structure of a function.
IExposedMethodsAlphaAn interface that SharedTree schema classes should implement to expose their methods to the LLM.
IExposedPropertiesAlphaAn interface that SharedTree schema classes should implement to expose their properties to the LLM.
LoggerAlphaLogger interface for logging events from a SharedTreeSemanticAgent.
SemanticAgentOptionsAlphaOptions used to parameterize the creation of a SharedTreeSemanticAgent.
SharedTreeChatModelAlphaA plugin interface that handles queries from a SharedTreeSemanticAgent.
SharedTreeChatQueryDeprecated, AlphaA query from a user to a SharedTreeSemanticAgent.
TreeAgentAlphaAn agent that can analyze and edit a SharedTree.
TreeAgentAssistantMessageAlphaAn assistant message containing the model's text response (when no tool call is made).
TreeAgentOptionsAlphaOptions for creating a tree agent via createTreeAgent(model, tree, options).
TreeAgentSystemMessageAlphaA system message providing context to the model.
TreeAgentToolCallMessageAlphaAn assistant message requesting a tool call (e.g. to edit the tree).
TreeAgentToolResultMessageAlphaA tool result message containing the outcome of a tool invocation.
TreeAgentUserMessageAlphaA user message containing a query or instruction.
TypeFactoryArrayAlphaRepresents an array type in the type factory system.
TypeFactoryBooleanAlphaRepresents a boolean type in the type factory system.
TypeFactoryDateAlphaRepresents a Date type in the type factory system.
TypeFactoryFunctionAlphaRepresents a function type in the type factory system.
TypeFactoryInstanceOfAlphaRepresents an instanceof type that references a SharedTree schema class in the type factory system.
TypeFactoryIntersectionAlphaRepresents an intersection type in the type factory system.
TypeFactoryLiteralAlphaRepresents a literal type (specific string, number, or boolean value) in the type factory system.
TypeFactoryMapAlphaRepresents a Map type in the type factory system.
TypeFactoryNullAlphaRepresents a null type in the type factory system.
TypeFactoryNumberAlphaRepresents a number type in the type factory system.
TypeFactoryObjectAlphaRepresents an object type with a fixed shape in the type factory system.
TypeFactoryOptionalAlphaRepresents an optional type modifier in the type factory system.
TypeFactoryPromiseAlphaRepresents a Promise type in the type factory system.
TypeFactoryReadonlyAlphaRepresents a readonly type modifier in the type factory system.
TypeFactoryRecordAlphaRepresents a record type (index signature) in the type factory system.
TypeFactoryStringAlphaRepresents a string type in the type factory system.
TypeFactoryTupleAlphaRepresents a tuple type with fixed-length items and optional rest elements in the type factory system.
TypeFactoryTypeAlphaBase interface for type factory types.
TypeFactoryUndefinedAlphaRepresents an undefined type in the type factory system.
TypeFactoryUnionAlphaRepresents a union type in the type factory system.
TypeFactoryUnknownAlphaRepresents an unknown type in the type factory system.
TypeFactoryVoidAlphaRepresents a void type in the type factory system.

Classes

ClassAlertsModifiersDescription
PropertyDefAlphaA property definition class that describes the structure of the property
SharedTreeSemanticAgentAlphasealedAn agent that uses a SharedTreeChatModel to interact with a SharedTree.

Types

TypeAliasAlertsDescription
ArgAlphaA type that represents a function argument.
ArgsTupleAlphaA utility type that extracts the argument types from a function definition.
AsynchronousEditorAlphaAn asynchronous function that executes a string of JavaScript code to perform an edit within a SharedTreeSemanticAgent.
BindableSchemaAlphaA type that represents an object schema class.
CtorAlphaA type that represents a constructor function.
MethodKeysAlphaA utility type that extracts the method keys from a given type.
SynchronousEditorAlphaA synchronous function that executes a string of JavaScript code to perform an edit within a SharedTreeSemanticAgent.
TreeAgentChatMessageAlphaA role-tagged message in a tree agent conversation.
TreeAgentChatResponseAlphaA response from a SharedTreeChatModel after invoking it with a message history.
TreeViewAlphaA SharedTree view for use by a SharedTreeSemanticAgent.
TypeFactoryFunctionParameterAlphaRepresents a function parameter as a tuple of [name, type].
TypeFactoryTypeKindAlphaType kinds for the type factory type system.
ViewOrTreeAlphaA value that is either a TreeView or a subtree within a TreeView.

Functions

FunctionAlertsReturn TypeDescription
buildFunc(def, args)AlphaFunctionDef<Args, Return, Rest>A utility function to build a function definition.
createContext(tree)AlphaContext<TSchema>Creates a Context for the given subtree.
createTreeAgent(model, tree, options)AlphaTreeAgentCreates an agent that can analyze and edit a SharedTree.
executeSemanticEditing(model, tree, prompt, options)AlphaPromise<string>Executes semantic editing on a tree.
isTypeFactoryType(value)Alphavalue is TypeFactoryTypeType guard to check if a value is a type factory type.

Variables

VariableAlertsModifiersTypeDescription
exposeMethodsSymbolAlphareadonlyunique symbolA symbol used to expose methods to the LLM.
exposePropertiesSymbolAlphareadonlyunique symbolA symbol used to expose properties to the LLM.
llmDefaultAlphareadonlyunique symbolInclude this property in a field's schema metadata to indicate that the field's value should be generated via a provided function rather than by the LLM.
typeFactoryAlphareadonly{ string(): TypeFactoryString; number(): TypeFactoryNumber; boolean(): TypeFactoryBoolean; date(): TypeFactoryDate; void(): TypeFactoryVoid; undefined(): TypeFactoryUndefined; null(): TypeFactoryNull; unknown(): TypeFactoryUnknown; array(element: TypeFactoryType): TypeFactoryArray; promise(innerType: TypeFactoryType): TypeFactoryPromise; object(shape: Record<string, TypeFactoryType>): TypeFactoryObject; record(keyType: TypeFactoryType, valueType: TypeFactoryType): TypeFactoryRecord; map(keyType: TypeFactoryType, valueType: TypeFactoryType): TypeFactoryMap; tuple(items: readonly TypeFactoryType[], rest?: TypeFactoryType): TypeFactoryTuple; union(options: readonly TypeFactoryType[]): TypeFactoryUnion; intersection(types: readonly TypeFactoryType[]): TypeFactoryIntersection; literal(value: string | number | boolean): TypeFactoryLiteral; optional(innerType: TypeFactoryType): TypeFactoryOptional; readonly(innerType: TypeFactoryType): TypeFactoryReadonly; function(parameters: readonly TypeFactoryFunctionParameter[], returnType: TypeFactoryType, restParameter?: TypeFactoryFunctionParameter): TypeFactoryFunction; instanceOf<T extends TreeNodeSchemaClass>(schema: T): TypeFactoryInstanceOf; }Namespace containing type factory functions.

Function Details

buildFunc

A utility function to build a function definition.

This API is provided as an alpha preview and may change without notice.

To use, import via @fluidframework/tree-agent/alpha.

For more information about our API support guarantees, see here.

Signature

export declare function buildFunc<const Return extends TypeFactoryType, const Args extends readonly Arg[], const Rest extends TypeFactoryType | null = null>(def: {
description?: string;
returns: Return;
rest?: Rest;
}, ...args: Args): FunctionDef<Args, Return, Rest>;
Type Parameters
ParameterConstraintDefaultDescription
ReturnTypeFactoryType
Argsreadonly Arg[]
RestTypeFactoryType | nullnull

Parameters

ParameterTypeDescription
def{ description?: string; returns: Return; rest?: Rest; }
argsArgs

Returns

Return type: FunctionDef<Args, Return, Rest>

createContext

Creates a Context for the given subtree.

This API is provided as an alpha preview and may change without notice.

To use, import via @fluidframework/tree-agent/alpha.

For more information about our API support guarantees, see here.

Signature

export declare function createContext<TSchema extends ImplicitFieldSchema>(tree: ViewOrTree<TSchema>): Context<TSchema>;
Type Parameters
ParameterConstraintDescription
TSchemaImplicitFieldSchema

Parameters

ParameterTypeDescription
treeViewOrTree<TSchema>

Returns

Return type: Context<TSchema>

createTreeAgent

Creates an agent that can analyze and edit a SharedTree.

This API is provided as an alpha preview and may change without notice.

To use, import via @fluidframework/tree-agent/alpha.

For more information about our API support guarantees, see here.

Signature

export declare function createTreeAgent<TSchema extends ImplicitFieldSchema>(model: SharedTreeChatModel, tree: ViewOrTree<TSchema>, options?: TreeAgentOptions<TSchema>): TreeAgent;
Type Parameters
ParameterConstraintDescription
TSchemaImplicitFieldSchema

Parameters

ParameterModifiersTypeDescription
modelSharedTreeChatModelThe chat model. Must implement invoke(history) and have editToolName set.
treeViewOrTree<TSchema>The tree or subtree to edit.
optionsoptionalTreeAgentOptions<TSchema>Optional configuration.

Returns

A TreeAgent.

Return type: TreeAgent

executeSemanticEditing

Executes semantic editing on a tree.

This API is provided as an alpha preview and may change without notice.

To use, import via @fluidframework/tree-agent/alpha.

For more information about our API support guarantees, see here.

Signature

export declare function executeSemanticEditing<TSchema extends ImplicitFieldSchema>(model: SharedTreeChatModel, tree: ViewOrTree<TSchema>, prompt: string, options?: ExecuteSemanticEditingOptions<TSchema>): Promise<string>;
Type Parameters
ParameterConstraintDescription
TSchemaImplicitFieldSchema

Parameters

ParameterModifiersTypeDescription
modelSharedTreeChatModelThe chat model. Must implement invoke(history) and have editToolName set.
treeViewOrTree<TSchema>The tree or subtree to edit.
promptstringThe user's edit instruction.
optionsoptionalExecuteSemanticEditingOptions<TSchema>Optional configuration.

Returns

The model's text response.

Return type: Promise<string>

isTypeFactoryType

Type guard to check if a value is a type factory type.

This API is provided as an alpha preview and may change without notice.

To use, import via @fluidframework/tree-agent/alpha.

For more information about our API support guarantees, see here.

Signature

export declare function isTypeFactoryType(value: unknown): value is TypeFactoryType;

Parameters

ParameterTypeDescription
valueunknown

Returns

Return type: value is TypeFactoryType

Variable Details

exposeMethodsSymbol

A symbol used to expose methods to the LLM.

This API is provided as an alpha preview and may change without notice.

To use, import via @fluidframework/tree-agent/alpha.

For more information about our API support guarantees, see here.

Signature

exposeMethodsSymbol: unique symbol

Type: unique symbol

exposePropertiesSymbol

A symbol used to expose properties to the LLM.

This API is provided as an alpha preview and may change without notice.

To use, import via @fluidframework/tree-agent/alpha.

For more information about our API support guarantees, see here.

Signature

exposePropertiesSymbol: unique symbol

Type: unique symbol

llmDefault

Include this property in a field's schema metadata to indicate that the field's value should be generated via a provided function rather than by the LLM.

This API is provided as an alpha preview and may change without notice.

To use, import via @fluidframework/tree-agent/alpha.

For more information about our API support guarantees, see here.

Signature

llmDefault: unique symbol

Type: unique symbol

Example

class Object extends schemaFactory.object("Object", {
created: sf.required(sf.number, {
custom: {
// The LLM will ignore this field, and instead it will be populated with the result of the function
[llmDefault]: () => Date.now(),
},
}),
}) {};

typeFactory

Namespace containing type factory functions.

This API is provided as an alpha preview and may change without notice.

To use, import via @fluidframework/tree-agent/alpha.

For more information about our API support guarantees, see here.

Signature

typeFactory: {
string(): TypeFactoryString;
number(): TypeFactoryNumber;
boolean(): TypeFactoryBoolean;
date(): TypeFactoryDate;
void(): TypeFactoryVoid;
undefined(): TypeFactoryUndefined;
null(): TypeFactoryNull;
unknown(): TypeFactoryUnknown;
array(element: TypeFactoryType): TypeFactoryArray;
promise(innerType: TypeFactoryType): TypeFactoryPromise;
object(shape: Record<string, TypeFactoryType>): TypeFactoryObject;
record(keyType: TypeFactoryType, valueType: TypeFactoryType): TypeFactoryRecord;
map(keyType: TypeFactoryType, valueType: TypeFactoryType): TypeFactoryMap;
tuple(items: readonly TypeFactoryType[], rest?: TypeFactoryType): TypeFactoryTuple;
union(options: readonly TypeFactoryType[]): TypeFactoryUnion;
intersection(types: readonly TypeFactoryType[]): TypeFactoryIntersection;
literal(value: string | number | boolean): TypeFactoryLiteral;
optional(innerType: TypeFactoryType): TypeFactoryOptional;
readonly(innerType: TypeFactoryType): TypeFactoryReadonly;
function(parameters: readonly TypeFactoryFunctionParameter[], returnType: TypeFactoryType, restParameter?: TypeFactoryFunctionParameter): TypeFactoryFunction;
instanceOf<T extends TreeNodeSchemaClass>(schema: T): TypeFactoryInstanceOf;
}

Type: { string(): TypeFactoryString; number(): TypeFactoryNumber; boolean(): TypeFactoryBoolean; date(): TypeFactoryDate; void(): TypeFactoryVoid; undefined(): TypeFactoryUndefined; null(): TypeFactoryNull; unknown(): TypeFactoryUnknown; array(element: TypeFactoryType): TypeFactoryArray; promise(innerType: TypeFactoryType): TypeFactoryPromise; object(shape: Record<string, TypeFactoryType>): TypeFactoryObject; record(keyType: TypeFactoryType, valueType: TypeFactoryType): TypeFactoryRecord; map(keyType: TypeFactoryType, valueType: TypeFactoryType): TypeFactoryMap; tuple(items: readonly TypeFactoryType[], rest?: TypeFactoryType): TypeFactoryTuple; union(options: readonly TypeFactoryType[]): TypeFactoryUnion; intersection(types: readonly TypeFactoryType[]): TypeFactoryIntersection; literal(value: string | number | boolean): TypeFactoryLiteral; optional(innerType: TypeFactoryType): TypeFactoryOptional; readonly(innerType: TypeFactoryType): TypeFactoryReadonly; function(parameters: readonly TypeFactoryFunctionParameter[], returnType: TypeFactoryType, restParameter?: TypeFactoryFunctionParameter): TypeFactoryFunction; instanceOf<T extends TreeNodeSchemaClass>(schema: T): TypeFactoryInstanceOf; }