Skip to main content
The structured_writing tool is designed for generating long-form, coherent content that requires a specific structure or outline. Unlike standard chat responses which are often linear and limited in length, this tool can orchestrate the creation of complex documents like reports, blog posts, white papers, or technical specifications. It works by taking a high-level intent and a structured plan, then systematically generating content for each section, maintaining context and consistency throughout the document.

When to Use This Tool

Use structured_writing when you need to:
  • Draft Long Documents: Create content that exceeds the typical output limits of a single LLM call.
  • Follow a Specific Outline: Ensure the output adheres strictly to a predefined structure (e.g., Introduction -> Methodology -> Results -> Conclusion).
  • Maintain Consistency: Generate multiple sections that need to reference each other or maintain a consistent tone.
  • Collaborate with Sub-Agents: Delegate specific sections to specialized sub-agents (e.g., a “Data Analyst” agent for the results section).

Input Parameters

The tool accepts the following parameters: *Either structured_plan or plan_document_id must be provided.

Plan Structure

The structured_plan is a recursive JSON object where each node represents a section of the document. This allows you to create complex hierarchies with chapters, sections, and subsections.

Output Structure

The tool returns the original plan enriched with the generated content.

Example Usage

Scenario: Writing a Quarterly Report

Input:
Result: The tool will generate the “Executive Summary” first. Then, carrying the context of what it just wrote, it will move to “Financial Performance”, ensuring it doesn’t contradict the summary. Finally, it writes the “Q4 Outlook”. The final output is a cohesive report.

Advanced Features

1. Sequential vs. Parallel Execution

  • Sequential: Writes sections one by one. The context (what was written previously) is passed to the next step. Best for narratives where flow and consistency are critical.
  • Parallel: Writes all sections simultaneously. Much faster, but sections cannot reference each other. Best for encyclopedic content or independent summaries.

2. Sub-Agent Delegation

You can assign specific sections to specialized agents by adding an agent_id to a part in the plan.
This allows you to mix generalist writing with specialist analysis in a single document.

3. Memory Modes

In sequential mode, you can control how much context is retained:
  • Classic: Summarizes the history when it gets too long. Good balance.
  • Specific: Re-analyzes the entire history for each new section to find relevant context. Slower but higher quality for complex documents.
  • None: No context is passed between sections (acts like parallel but runs sequentially).