In part 3 we looked at creating the researcher. As promised, today we’ll look at the author.

You’ll notice in the following code a great deal of similarity to what we’ve seen before. The goal is to create a code “template” that we can follow as we create any agent; departing only for the agent’s special requirements and abilities.
As usual, we start with the factory method:
def create_author_chain():
"""Creates the author chain."""
def author_invoke(state):
research = state.get("research_findings", [])
research_text = "\n\n".join(research) if research else "No research available."
prompt = author_prompt_template.format(
main_task=state.get("main_task", ""),
research_findings=research_text,
draft=state.get("draft", ""),
review_notes=state.get("review_notes", "")
)
try:
response = llm.invoke(prompt)
content = response.content if hasattr(response, 'content') else str(response)
return content if content else "Draft in progress..."
except Exception as e:
print(f"Author error: {e}")
return "Error generating draft. Please try again."
return author_invoke
# Creating a callable object
author_chain = create_author_chain()
Continue reading






















