ArtifactToolkit

class ArtifactToolkit(BaseToolkit):
A toolkit for creating and managing artifacts like HTML, SVG, charts, and diagrams. This toolkit enables agents to generate visual content that can be previewed in the CAMEL web application, similar to Claude’s artifact system. Supported artifact types:
  • HTML documents
  • SVG graphics
  • Mermaid flowcharts and diagrams
  • Code snippets (with syntax highlighting)
  • Markdown documents
  • LaTeX math expressions

_generate_artifact_id

def _generate_artifact_id(self, artifact_type: str):
Generate a unique artifact ID with microsecond precision.

create_html_artifact

def create_html_artifact(
    self,
    content: str,
    title: str = 'HTML Artifact',
    include_css: bool = True,
    css_styles: Optional[str] = None
):
Create an HTML artifact that can be rendered in the web interface. Parameters:
  • content (str): The HTML content to be displayed.
  • title (str, optional): Title for the artifact. Defaults to “HTML Artifact”. (default: "HTML Artifact")
  • include_css (bool, optional): Whether to include basic CSS styling. Defaults to True. (default: True)
  • css_styles (str, optional): Additional CSS styles to include.
Returns: Dict[str, Any]: A dictionary containing the artifact data with metadata.

_wrap_html_content

def _wrap_html_content(
    self,
    content: str,
    title: str,
    include_css: bool,
    css_styles: Optional[str]
):
Wrap content in a complete HTML document with optional styling.

_create_html_document

def _create_html_document(
    self,
    title: str,
    body_content: str,
    head_content: str = '',
    body_class: str = ''
):
Create a complete HTML document with consistent structure.

_get_base_styles

def _get_base_styles(self):
Get base CSS styles used across all artifacts.

create_svg_artifact

def create_svg_artifact(
    self,
    svg_content: str,
    title: str = 'SVG Graphic',
    width: Optional[int] = None,
    height: Optional[int] = None
):
Create an SVG artifact for vector graphics. Parameters:
  • svg_content (str): The SVG content (can be just the inner elements or complete SVG).
  • title (str, optional): Title for the artifact. Defaults to “SVG Graphic”. (default: "SVG Graphic")
  • width (int, optional): Width of the SVG. If not provided, uses SVG’s viewBox or defaults.
  • height (int, optional): Height of the SVG. If not provided, uses SVG’s viewBox or defaults.
Returns: Dict[str, Any]: A dictionary containing the SVG artifact data.

create_mermaid_flowchart

def create_mermaid_flowchart(
    self,
    flowchart_definition: str,
    title: str = 'Flowchart',
    direction: str = 'TD'
):
Create a Mermaid flowchart artifact. Parameters:
  • flowchart_definition (str): The Mermaid flowchart definition.
  • title (str, optional): Title for the flowchart. Defaults to “Flowchart”. (default: "Flowchart")
  • direction (str, optional): Flow direction (TD, LR, BT, RL). Defaults to “TD”. (default: "TD")
Returns: Dict[str, Any]: A dictionary containing the Mermaid flowchart data.

create_code_artifact

def create_code_artifact(
    self,
    code: str,
    language: str = 'python',
    title: str = 'Code Snippet',
    show_line_numbers: bool = True,
    theme: str = 'github'
):
Create a code artifact with syntax highlighting. Parameters:
  • code (str): The source code content.
  • language (str, optional): Programming language for syntax highlighting. Defaults to “python”. (default: "python")
  • title (str, optional): Title for the code artifact. Defaults to “Code Snippet”. (default: "Code Snippet")
  • show_line_numbers (bool, optional): Whether to show line numbers. Defaults to True. (default: True)
  • theme (str, optional): Syntax highlighting theme. Defaults to “github”. (default: "github")
Returns: Dict[str, Any]: A dictionary containing the code artifact data.

create_markdown_artifact

def create_markdown_artifact(
    self,
    markdown_content: str,
    title: str = 'Document',
    include_toc: bool = False,
    theme: str = 'github'
):
Create a Markdown document artifact with rendering. Parameters:
  • markdown_content (str): The Markdown content.
  • title (str, optional): Title for the document. Defaults to “Document”. (default: "Document")
  • include_toc (bool, optional): Whether to include a table of contents. Defaults to False. (default: False)
  • theme (str, optional): Styling theme for the document. Defaults to “github”. (default: "github")
Returns: Dict[str, Any]: A dictionary containing the Markdown artifact data.

create_latex_math

def create_latex_math(
    self,
    latex_expression: str,
    title: str = 'Mathematical Expression',
    display_mode: str = 'block',
    show_source: bool = False
):
Create a LaTeX mathematical expression artifact. Parameters:
  • latex_expression (str): The LaTeX mathematical expression.
  • title (str, optional): Title for the math artifact. Defaults to “Mathematical Expression”. (default: "Mathematical Expression")
  • display_mode (str, optional): Display mode - “block” for centered equations, “inline” for text-style. Defaults to “block”. (default: "block")
  • show_source (bool, optional): Whether to show the LaTeX source code. Defaults to False. (default: False)
Returns: Dict[str, Any]: A dictionary containing the LaTeX math artifact data.

get_artifact_info

def get_artifact_info(self, artifact: Dict[str, Any]):
Get formatted information about an artifact. Parameters:
  • artifact (Dict[str, Any]): The artifact dictionary.
Returns: str: Formatted information about the artifact.

get_tools

def get_tools(self):
Returns: List[FunctionTool]: A list of FunctionTool objects representing the functions in the toolkit.