Merge https://github.com/google/adk-python/pull/3394 This PR corrects misspellings identified by the [check-spelling action](https://github.com/marketplace/actions/check-spelling) Note: while I use tooling to identify errors, the tooling doesn't _actually_ provide the corrections, I'm picking them on my own. I'm a human, and I may make mistakes. ### Testing Plan The misspellings have been reported at https://github.com/jsoref/adk-python/actions/runs/19056081305/attempts/1#summary-54426435973 The action reports that the changes in this PR would make it happy: https://github.com/jsoref/adk-python/actions/runs/19056081446/attempts/1#summary-54426436321 **Unit Tests:** - [ ] I have added or updated unit tests for my change. - [ ] All unit tests pass locally. _Please include a summary of passed `pytest` results._ **Manual End-to-End (E2E) Tests:** _Please provide instructions on how to manually test your changes, including any necessary setup or configuration. Please provide logs or screenshots to help reviewers better understand the fix._ ### Checklist - [x] I have read the [CONTRIBUTING.md](https://github.com/google/adk-python/blob/main/CONTRIBUTING.md) document. - [x] I have performed a self-review of my own code. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have added tests that prove my fix is effective or that my feature works. - [ ] New and existing unit tests pass locally with my changes. - [ ] I have manually tested my changes end-to-end. - [ ] Any dependent changes have been merged and published in downstream modules. ### Additional context - https://github.com/google/adk-python/pull/3382#issuecomment-3488654110 COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/3394 from jsoref:spelling-contributing c3d5e342c4350f7cae9f8f0c6638b176f2e30e80 PiperOrigin-RevId: 828659867
Custom Code Executor Agent Sample
This directory contains a sample agent that demonstrates how to customize a
CodeExecutor to perform environment setup before executing code. The specific
example shows how to add support for Japanese fonts in matplotlib plots by
subclassing VertexAiCodeExecutor.
Overview
This sample showcases a powerful pattern for customizing code execution
environments. By extending a base CodeExecutor, you can inject setup code to
prepare the environment before a user's code is run. This enables advanced use
cases that require specific configurations, in this case, adding custom fonts.
Key Concept: CodeExecutor Customization
The Agent Development Kit (ADK) allows for powerful customization of code
execution by extending existing CodeExecutor classes. By subclassing an
executor (e.g., VertexAiCodeExecutor) and overriding its execute_code
method, you can inject custom logic to:
- Modify the code before it's executed.
- Add files to the execution environment.
- Process the results after execution.
Example: Adding Japanese Font Support
The CustomCodeExecutor in this sample solves a common issue where non-Latin
characters do not render correctly in plots generated by matplotlib due to
missing fonts in the execution environment.
It achieves this by: 1. Subclassing VertexAiCodeExecutor: It inherits all
the functionality of the standard Vertex AI code executor. 2. Overriding
execute_code: Before calling the parent's execute_code method, it performs
the following steps: a. Downloads a Japanese font file (NotoSerifJP). b. Adds
the font file to the list of files to be uploaded to the execution environment.
c. Prepends a Python code snippet to the user's code. This snippet uses
matplotlib.font_manager to register the newly available font file, making it
available for plotting. 3. Executing the modified code: The combined code
(setup snippet + original code) is then executed in the Vertex AI environment,
which now has the Japanese font available for matplotlib.
This ensures that any plots generated during the agent's session can correctly display Japanese characters.
How to use
Prerequisites
Ensure you have configured your environment for using Google Cloud Vertex AI. You will need to have a Google Cloud Project with the Vertex AI API enabled.
Running the agent
You can run this agent using the ADK CLI.
To interact with the agent through the command line:
adk run contributing/samples/custom_code_execution "Plot a bar chart with these categories and values: {'リンゴ': 10, 'バナナ': 15, 'オレンジ': 8}. Title the chart '果物の在庫' (Fruit Stock)."
To use the web interface:
adk web contributing/samples/
Then select custom_code_execution from the list of agents and interact with
it.