View Source SwarmEx.Tools.CodeInterpreter (SwarmEx v0.2.0)
DEPRECATED: This module is deprecated. Use a regular module with functions instead.
Migration Guide
Instead of using the Tool behavior, implement code interpretation as regular functions:
defmodule MyCodeInterpreter do
def execute_code(language, code, opts \ []) do
case language do
"elixir" -> execute_elixir(code, opts)
"python" -> execute_python(code, opts)
_ -> {:error, :unsupported_language}
end
end
defp execute_elixir(code, opts) do
# Implement sandboxed Elixir code execution
{:error, :not_implemented}
end
defp execute_python(code, opts) do
# Implement Python code execution via port
{:error, :not_implemented}
end
defp validate_code(language, code) do
# Implement validation logic
:ok
end
end
Then use it directly in your agent:
defmodule MyAgent do
use SwarmEx.Agent
def handle_message(%{language: lang, code: code} = msg, state) do
case MyCodeInterpreter.execute_code(lang, code) do
{:ok, result} -> {:ok, result, state}
error -> error
end
end
end