multi-agent system for creating poetry with accompanying text-to-speech and music.
Multi-Agent System: Poetry, Speech, and Music
POEM: 八月7日凌晨
七月初七鹊桥边,
银汉迢迢星光寒。
人间几度离合苦,
梦里相逢泪湿衫。
晓风残月催人醒,
又是人间一日忙。
愿得此情长久在,
不负韶华不负卿。
This system will be composed of three distinct agents, each with a specialized function. They will work in a sequential workflow, passing the output of one agent as the input to the next.
Agent Roles:
Poet Agent: This agent's primary role is to generate a poem or limerick based on a theme or content provided by the user. It will focus on creativity, structure, and lyrical quality.
Voice Agent: This agent will take the text of the poem and convert it into speech. It will be responsible for creating a clear and expressive audio representation of the poem.
Music Agent: This agent will compose a short piece of music to serve as a background for the spoken poem. The goal is to create an atmosphere that complements the mood and theme of the poetry.
Workflow:
Input: The user provides a theme or some initial content to the PoetryAgent.
Poem Generation: The PoetAgent uses the input to create a poem.
Text-to-Speech: The generated poem is passed to the VoiceAgent, which converts the text into an audio file.
Music Composition: The MusicAgent creates a musical piece.
Final Output: The system will provide the poem's text, the spoken version of the poem, and the background music.
bosonai/higgs-audio-v2-generation-3B-base
https://huggingface.co/bosonai/higgs-audio-v2-generation-3B-base
TextToSpeechTool: This tool now connects to the Gradio server you specified. It uses an async function to handle the connection and the tool call.
MCP Connection: The tool uses stdio_client and ClientSession from the mcp library to communicate with the server.
Task Dependency: I've added a context to the speak_poem_task to ensure it runs after the write_poem_task is complete.
facebook/musicgen-small
Start the main agent server:
uv run agent.pyExpected output:
🚀 Agent server starting on http://localhost:8000
Test the full poetry workflow via HTTP:
curl -X POST http://localhost:8000/runs \
-H "Content-Type: application/json" \
-d '{
"agent_name": "poetry_agent",
"input": [
{
"role": "user",
"parts": [
{
"content": "春天的花朵",
"content_type": "text/plain"
}
]
}
]
}'