agentkit.base_node
Classes
|
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.
- query_llm
Function to query the LLM.
- Type:
Callable
- _compose_prompt
ComposePrompt object.
- Type:
- after_query
AfterQuery object.
- Type:
- error_msg_fn
Function to add error message to the prompt.
- Type:
Callable
- 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:
- 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:
- get_dependencies_inc_order()
Get the dependencies (edges) and order (non-dependency edges) of the node.
- Returns:
List of dependencies.
- Return type:
- get_token_counts()
Get the LLM token counts for the specific node since instantiation.
- Returns:
Token counts for the node.
- Return type:
- 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.