Skip to content

refactor: PythonGenerator.Generate mutates caller's AgentConfig via pointer #204

@groundnuty

Description

@groundnuty

Description

PythonGenerator.Generate receives *common.AgentConfig and mutates several fields in-place:

// internal/cli/agent/frameworks/adk/python/generator.go

func (g *PythonGenerator) Generate(agentConfig *common.AgentConfig) error {
    agentConfig.Name = validators.PythonSafeName(agentConfig.Name)  // line 36
    // ...
    agentConfig.Framework = "adk"    // line 51
    agentConfig.Language = "python"  // line 52
}

The caller in init.go currently works correctly because it uses a separate agentName string variable for post-Generate output. However, any future code that reads agentConfig.Name after calling Generate would observe the transformed value (my_agent) instead of the original (my-agent).

This is a latent correctness risk - the function silently changes its input without the caller expecting it.

Suggested Fix

Work on a local copy inside Generate instead of mutating the caller's struct:

func (g *PythonGenerator) Generate(agentConfig *common.AgentConfig) error {
    if agentConfig == nil {
        return fmt.Errorf("agent config is required")
    }

    cfg := *agentConfig
    cfg.Name = validators.PythonSafeName(agentConfig.Name)
    cfg.Framework = "adk"
    cfg.Language = "python"

    // use cfg everywhere below
}

Change Type

/kind cleanup

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions