Python Code Execution Skill#

class council.skills.python.PythonCodeExecutionSkill(env_var: Mapping[str, str] | None = None, decode_stdout: bool = True)[source]#

Bases: SkillBase

Skills that execute python code and provides the results.

The python code is retrieved from the message content from context.try_last_message, looking for a markdown python code block.

The return message data contains a dictionary with the status code, stdout and stderr.

__init__(env_var: Mapping[str, str] | None = None, decode_stdout: bool = True) None[source]#

Initialize a new instance

Parameters:
  • env_var – Optional list of environment variable to be set for the code execution

  • decode_stdout – either or not the stdout should be returns as a string (True), or as a bytes (False)

build_success_message(message: str, data: Any | None = None) ChatMessage#

Builds a success message for the skill with the provided message and optional data.

Parameters:
  • message (str) – The success message.

  • data (Any, optional) – Additional data to include in the message. Defaults to None.

Returns:

The success message.

Return type:

ChatMessage

Raises:

None

execute(context: SkillContext) ChatMessage[source]#

Executes the skill on the provided chain context and budget.

Parameters:

context (SkillContext) – The context for executing the skill.

Returns:

The result of skill execution.

Return type:

ChatMessage

Raises:

None

execute_skill(context: SkillContext) ChatMessage#

Skill execution

property name#

Property getter for the skill name.

Returns:

The name of the skill.

Return type:

str

Raises:

None

render_as_dict(include_children: bool = True) Dict[str, Any]#

returns the graph of operation as a dictionary

render_as_json() str#

returns the graph of operation as a JSON string

run_in_current_thread(context: ChainContext, iteration_context: Option[IterationContext]) None#

Run the skill in the current thread

run_skill(context: ChainContext, executor: ThreadPoolExecutor) None#

Run the skill in a different thread, and await for completion