This paper proposes DynaSwarm, a dynamic framework for enhancing large-scale language model (LLM)-based multi-agent systems (MAS) to overcome the limitations of existing MASs that rely on static, manually designed collaborative graph structures. DynaSwarm leverages two key innovations: (1) graph structure optimization via the actor-critic reinforcement learning (A2C) mechanism, which improves stability compared to existing reinforcement learning (RL) methods, and (2) a dynamic graph selector that adaptively selects the optimal graph structure for each input sample via parameter-efficient LLM fine-tuning. This allows DynaSwarm to dynamically route queries through a network of specialized agents by exploiting sample-specific features, rather than relying on a fixed graph architecture that applies to all samples. Furthermore, we propose a method for fine-tuning a demo searcher to maximize the effectiveness of in-context learning (ICL). Extensive experiments on question answering, mathematical reasoning, and coding tasks demonstrate that DynaSwarm consistently outperforms state-of-the-art single-agent and MAS baseline models across multiple LLM backbones.