agentkit.base_node

Classes

BaseNode(key, prompt, graph, query_llm, ...)

Base class for a node in the graph.

class agentkit.base_node.BaseNode(key: str, prompt: str, graph: ~agentkit.graph.Graph, query_llm: ~collections.abc.Callable, compose_prompt: ~agentkit.compose_prompt.BaseComposePrompt, after_query: ~agentkit.after_query.BaseAfterQuery | None = None, error_msg_fn: ~collections.abc.Callable[[list, str, ~agentkit.exceptions.AfterQueryError], list] = <function error_msg_default>, verbose: bool = False, token_counter: ~collections.abc.Callable | None = None)

Base class for a node in the graph.

Each node in the graph is an instance of the BaseNode class. The node is evaluated by querying the LLM with a prompt.

key

Unique key for the node.

Type:

str

prompt

Prompt for the node.

Type:

str

result

Result of the node evaluation.

Type:

str

temporary_skip

Flag to skip the node evaluation.

Type:

bool

graph

Graph object.

Type:

Graph

adjacent_to

List of nodes that are adjacent to this node.

Type:

list

adjacent_from

List of nodes that are adjacent from this node.

Type:

list

evaluate_after

List of nodes that are evaluated after this node.

Type:

list

counts

List of token counts.

Type:

list

query_llm

Function to query the LLM.

Type:

Callable

_compose_prompt

ComposePrompt object.

Type:

BaseComposePrompt

after_query

AfterQuery object.

Type:

BaseAfterQuery

error_msg_fn

Function to add error message to the prompt.

Type:

Callable

verbose

Verbose flag. Node will print the prompt and answer.

Type:

bool

markdown

Markdown flag. Enables markdown output.

Type:

bool

token_counter

Function to count tokens.

Type:

Callable

evaluate()

Evaluate the node by querying the LLM.

Retries the AfterQuery with the LLM up to 3 times in case of an error.

Returns:

Result of the node evaluation.

Return type:

str

Raises:

AssertionError – If any dependency of the node has not been evaluated.

get_dependencies()

Get the dependencies (edges) of the node.

Returns:

List of dependencies.

Return type:

list

get_dependencies_inc_order()

Get the dependencies (edges) and order (non-dependency edges) of the node.

Returns:

List of dependencies.

Return type:

list

get_token_counts()

Get the LLM token counts for the specific node since instantiation.

Returns:

Token counts for the node.

Return type:

dict

skip_turn()

Temporarily skip the node evaluation. The previous result of the node will be reused.

Raises:

AssertionError – If the node has never been evaluated.