diff --git a/docs/edge/ar/guides/agents/secure-agent-design.mdx b/docs/edge/ar/guides/agents/secure-agent-design.mdx index 80941c2c4..dc52cc4ae 100644 --- a/docs/edge/ar/guides/agents/secure-agent-design.mdx +++ b/docs/edge/ar/guides/agents/secure-agent-design.mdx @@ -293,24 +293,36 @@ analyst = Agent( from crewai.flow.flow import Flow, listen, start from pydantic import BaseModel +class OutreachNotes(BaseModel): + claims: list[str] + sources: list[str] + class PipelineState(BaseModel): topic: str = "" - notes: list[str] = [] + notes: OutreachNotes | None = None email_status: str = "" class SecureOutreachFlow(Flow[PipelineState]): @start() def research(self): result = researcher.kickoff( - f"Extract factual notes about {self.state.topic}." + f"Extract factual notes about {self.state.topic}.", + response_format=OutreachNotes, ) - self.state.notes = [result.raw] + notes = result.pydantic + if not isinstance(notes, OutreachNotes) or not notes.claims or not notes.sources: + raise ValueError("Research must return validated OutreachNotes.") + self.state.notes = notes @listen(research) def send(self): - approved = "\n".join(self.state.notes) + notes = self.state.notes + if notes is None: + raise ValueError("No validated notes to send.") result = sender.kickoff( - f"Send outreach using only these notes:\n{approved}" + "Send outreach using only these claims and sources:\n" + f"claims={notes.claims}\n" + f"sources={notes.sources}" ) self.state.email_status = result.raw ``` diff --git a/docs/edge/en/guides/agents/secure-agent-design.mdx b/docs/edge/en/guides/agents/secure-agent-design.mdx index ee910adef..7d5e455f5 100644 --- a/docs/edge/en/guides/agents/secure-agent-design.mdx +++ b/docs/edge/en/guides/agents/secure-agent-design.mdx @@ -293,24 +293,36 @@ analyst = Agent( from crewai.flow.flow import Flow, listen, start from pydantic import BaseModel +class OutreachNotes(BaseModel): + claims: list[str] + sources: list[str] + class PipelineState(BaseModel): topic: str = "" - notes: list[str] = [] + notes: OutreachNotes | None = None email_status: str = "" class SecureOutreachFlow(Flow[PipelineState]): @start() def research(self): result = researcher.kickoff( - f"Extract factual notes about {self.state.topic}." + f"Extract factual notes about {self.state.topic}.", + response_format=OutreachNotes, ) - self.state.notes = [result.raw] + notes = result.pydantic + if not isinstance(notes, OutreachNotes) or not notes.claims or not notes.sources: + raise ValueError("Research must return validated OutreachNotes.") + self.state.notes = notes @listen(research) def send(self): - approved = "\n".join(self.state.notes) + notes = self.state.notes + if notes is None: + raise ValueError("No validated notes to send.") result = sender.kickoff( - f"Send outreach using only these notes:\n{approved}" + "Send outreach using only these claims and sources:\n" + f"claims={notes.claims}\n" + f"sources={notes.sources}" ) self.state.email_status = result.raw ``` diff --git a/docs/edge/ko/guides/agents/secure-agent-design.mdx b/docs/edge/ko/guides/agents/secure-agent-design.mdx index d8e50bda2..a5ce9d125 100644 --- a/docs/edge/ko/guides/agents/secure-agent-design.mdx +++ b/docs/edge/ko/guides/agents/secure-agent-design.mdx @@ -293,24 +293,36 @@ analyst = Agent( from crewai.flow.flow import Flow, listen, start from pydantic import BaseModel +class OutreachNotes(BaseModel): + claims: list[str] + sources: list[str] + class PipelineState(BaseModel): topic: str = "" - notes: list[str] = [] + notes: OutreachNotes | None = None email_status: str = "" class SecureOutreachFlow(Flow[PipelineState]): @start() def research(self): result = researcher.kickoff( - f"Extract factual notes about {self.state.topic}." + f"Extract factual notes about {self.state.topic}.", + response_format=OutreachNotes, ) - self.state.notes = [result.raw] + notes = result.pydantic + if not isinstance(notes, OutreachNotes) or not notes.claims or not notes.sources: + raise ValueError("Research must return validated OutreachNotes.") + self.state.notes = notes @listen(research) def send(self): - approved = "\n".join(self.state.notes) + notes = self.state.notes + if notes is None: + raise ValueError("No validated notes to send.") result = sender.kickoff( - f"Send outreach using only these notes:\n{approved}" + "Send outreach using only these claims and sources:\n" + f"claims={notes.claims}\n" + f"sources={notes.sources}" ) self.state.email_status = result.raw ``` diff --git a/docs/edge/pt-BR/guides/agents/secure-agent-design.mdx b/docs/edge/pt-BR/guides/agents/secure-agent-design.mdx index c5017f2e1..71a109e43 100644 --- a/docs/edge/pt-BR/guides/agents/secure-agent-design.mdx +++ b/docs/edge/pt-BR/guides/agents/secure-agent-design.mdx @@ -293,24 +293,36 @@ analyst = Agent( from crewai.flow.flow import Flow, listen, start from pydantic import BaseModel +class OutreachNotes(BaseModel): + claims: list[str] + sources: list[str] + class PipelineState(BaseModel): topic: str = "" - notes: list[str] = [] + notes: OutreachNotes | None = None email_status: str = "" class SecureOutreachFlow(Flow[PipelineState]): @start() def research(self): result = researcher.kickoff( - f"Extract factual notes about {self.state.topic}." + f"Extract factual notes about {self.state.topic}.", + response_format=OutreachNotes, ) - self.state.notes = [result.raw] + notes = result.pydantic + if not isinstance(notes, OutreachNotes) or not notes.claims or not notes.sources: + raise ValueError("Research must return validated OutreachNotes.") + self.state.notes = notes @listen(research) def send(self): - approved = "\n".join(self.state.notes) + notes = self.state.notes + if notes is None: + raise ValueError("No validated notes to send.") result = sender.kickoff( - f"Send outreach using only these notes:\n{approved}" + "Send outreach using only these claims and sources:\n" + f"claims={notes.claims}\n" + f"sources={notes.sources}" ) self.state.email_status = result.raw ```