Skip to main content

codebolt.knowledge

Tools for managing knowledge graph templates, instances, records (nodes), and edges (relationships).

Available Tools

Template Tools

  • kg_template_create - Creates a new knowledge graph instance template with record kinds and edge types
  • kg_template_list - Lists all knowledge graph instance templates
  • kg_template_get - Gets a knowledge graph instance template by its ID
  • kg_template_delete - Deletes a knowledge graph instance template permanently

Instance Tools

  • kg_instance_create - Creates a new knowledge graph instance based on a template
  • kg_instance_list - Lists knowledge graph instances, optionally filtered by template ID
  • kg_instance_get - Gets a knowledge graph instance by its ID
  • kg_instance_delete - Deletes a knowledge graph instance and all its data permanently

Record Tools

  • kg_record_add - Adds a memory record (node) to a knowledge graph instance
  • kg_record_list - Lists memory records in an instance with optional filtering and pagination

Edge Tools

  • kg_edge_add - Adds an edge (relationship) between two records in a knowledge graph instance
  • kg_edge_list - Lists edges in an instance with optional filtering by kind, source, or target node

Tool Parameters

kg_template_create

Creates a new knowledge graph instance template defining the schema for records and edges.

ParameterTypeRequiredDescription
namestringYesThe name of the template
descriptionstringNoOptional description of the template
record_kindsarrayYesArray of record kinds defining the node types in the graph (objects with name, label, description, attributes)
edge_typesarrayYesArray of edge types defining the relationships in the graph (objects with name, label, description, from_kinds, to_kinds, attributes)

kg_template_list

Lists all knowledge graph instance templates.

ParameterTypeRequiredDescription
(none)--This tool takes no parameters

kg_template_get

Gets a knowledge graph instance template by its ID.

ParameterTypeRequiredDescription
template_idstringYesThe ID of the template to retrieve

kg_template_delete

Deletes a knowledge graph instance template permanently.

ParameterTypeRequiredDescription
template_idstringYesThe ID of the template to delete

kg_instance_create

Creates a new knowledge graph instance based on a template.

ParameterTypeRequiredDescription
template_idstringYesThe ID of the template to use for this instance
namestringYesThe name of the instance
descriptionstringNoOptional description of the instance

kg_instance_list

Lists knowledge graph instances, optionally filtered by template ID.

ParameterTypeRequiredDescription
template_idstringNoOptional template ID to filter instances by

kg_instance_get

Gets a knowledge graph instance by its ID.

ParameterTypeRequiredDescription
instance_idstringYesThe ID of the instance to retrieve

kg_instance_delete

Deletes a knowledge graph instance and all its data permanently.

ParameterTypeRequiredDescription
instance_idstringYesThe ID of the instance to delete

kg_record_add

Adds a memory record (node) to a knowledge graph instance.

ParameterTypeRequiredDescription
instance_idstringYesThe ID of the instance to add the record to
kindstringYesThe kind/type of the record (must match a record_kind in the template)
attributesobjectYesThe attributes/data of the record as a JSON object
valid_fromstringNoOptional: Start of validity period (ISO date string)
valid_tostringNoOptional: End of validity period (ISO date string)

kg_record_list

Lists memory records in a knowledge graph instance with optional filtering and pagination.

ParameterTypeRequiredDescription
instance_idstringYesThe ID of the instance to list records from
kindstringNoOptional: Filter by record kind
limitnumberNoOptional: Maximum number of records to return
offsetnumberNoOptional: Number of records to skip (for pagination)

kg_edge_add

Adds an edge (relationship) between two records in a knowledge graph instance.

ParameterTypeRequiredDescription
instance_idstringYesThe ID of the instance to add the edge to
kindstringYesThe kind/type of the edge (must match an edge_type in the template)
from_node_idstringYesThe ID of the source node (record)
to_node_idstringYesThe ID of the target node (record)
attributesobjectNoOptional: Additional attributes for the edge as a JSON object

kg_edge_list

Lists edges (relationships) in a knowledge graph instance with optional filtering.

ParameterTypeRequiredDescription
instance_idstringYesThe ID of the instance to list edges from
kindstringNoOptional: Filter by edge kind
from_node_idstringNoOptional: Filter by source node ID
to_node_idstringNoOptional: Filter by target node ID

Sample Usage

Creating a Template

const template = await codebolt.tools.executeTool(
"codebolt.knowledge",
"kg_template_create",
{
name: "Project Dependencies",
description: "Track project dependencies and relationships",
record_kinds: [
{
name: "project",
label: "Project",
attributes: {
name: { type: "string", required: true },
version: { type: "string" },
language: { type: "string" }
}
},
{
name: "library",
label: "Library",
attributes: {
name: { type: "string", required: true },
version: { type: "string" }
}
}
],
edge_types: [
{
name: "depends_on",
label: "Depends On",
from_kinds: ["project"],
to_kinds: ["library", "project"]
}
]
}
);

Creating an Instance

const instance = await codebolt.tools.executeTool(
"codebolt.knowledge",
"kg_instance_create",
{
template_id: "template-123",
name: "My Project Graph",
description: "Dependencies for my current project"
}
);

Adding Records and Edges

// Add a project record
const project = await codebolt.tools.executeTool(
"codebolt.knowledge",
"kg_record_add",
{
instance_id: "instance-456",
kind: "project",
attributes: {
name: "my-app",
version: "1.0.0",
language: "TypeScript"
}
}
);

// Add a library record
const library = await codebolt.tools.executeTool(
"codebolt.knowledge",
"kg_record_add",
{
instance_id: "instance-456",
kind: "library",
attributes: {
name: "express",
version: "4.18.0"
}
}
);

// Create a relationship between them
const edge = await codebolt.tools.executeTool(
"codebolt.knowledge",
"kg_edge_add",
{
instance_id: "instance-456",
kind: "depends_on",
from_node_id: "record-project-123",
to_node_id: "record-library-456"
}
);

Querying the Knowledge Graph

// List all templates
const templates = await codebolt.tools.executeTool(
"codebolt.knowledge",
"kg_template_list",
{}
);

// List instances for a template
const instances = await codebolt.tools.executeTool(
"codebolt.knowledge",
"kg_instance_list",
{ template_id: "template-123" }
);

// List records filtered by kind
const projects = await codebolt.tools.executeTool(
"codebolt.knowledge",
"kg_record_list",
{
instance_id: "instance-456",
kind: "project",
limit: 10
}
);

// List edges from a specific node
const dependencies = await codebolt.tools.executeTool(
"codebolt.knowledge",
"kg_edge_list",
{
instance_id: "instance-456",
from_node_id: "record-project-123"
}
);
info

Knowledge graphs use a template-instance pattern. Templates define the schema (what types of records and edges are allowed), while instances store the actual data. Records represent nodes/entities in the graph, and edges represent relationships between records. Records can optionally have validity periods (valid_from, valid_to) for temporal data.