I’m trying a 2-agent setup: Agent 1 just handles ...
# agents
p
I’m trying a 2-agent setup: Agent 1 just handles PII capture (asks/validates sensitive info). Agent 2 continues the main conversation. The goal is to separate sensitive data from the main flow for compliance. What’s the best way to structure this so the handoff is smooth and context is preserved?
r
Copy code
To implement a 2-agent setup where one agent (Agent 1) captures Personally Identifiable Information (PII) and another agent (Agent 2) continues the main conversation, you can leverage the existing structure of agents in your codebase. Here's a suggested approach:

1. **Define the PII Capture Agent**: Create a new agent that extends `DataCollectorAgent` for capturing sensitive information. This agent will handle the questions and validation for PII, such as name and email.

```python
   class PIICollectionAgent(DataCollectorAgent):
       key = "pii"
       label = "PII Collection"
       question = "Please provide your name and email."
       instruction = "I need to collect some information for compliance."
2. Define the Main Conversation Agent: This agent will handle the main flow of the conversation. It should be able to receive context from the PII Collection Agent.
Copy code
python
   class MainConversationAgent(BaseAgent):
       def __init__(self, job_context: JobContext, pii_data: dict) -> None:
           super().__init__(job_context=job_context)
           self.pii_data = pii_data  # Store PII data for use in the conversation

       async def on_enter(self) -> None:
           await self.session.say("Let's continue our conversation.")
           # Use self.pii_data as needed
3. Implement the Handoff Logic: In your flow management, after the PII Collection Agent has successfully captured the required information, you can transition to the Main Conversation Agent while passing the captured PII data.
Copy code
python
   async def handle_pii_collection(self):
       pii_agent = PIICollectionAgent(self.job_context)
       await pii_agent.on_enter()
       # Assuming collect method captures the PII and returns it
       pii_data = await pii_agent.collect(value)
       return MainConversationAgent(self.job_context, pii_data)
4. Preserve Context: Ensure that the session state is maintained throughout the transition. You can store the PII data in the session state or pass it directly to the Main Conversation Agent as shown above. 5. Flow Management: Use a flow manager to handle the transitions between agents. This can be done by checking the current state and determining which agent to invoke next based on the captured data. Here's a simplified flow diagram to illustrate the agent transition:
Copy code
mermaid
flowchart TD
    A["Start Conversation"] --> B["PIICollectionAgent"]
    B -->|Capture PII| C["MainConversationAgent"]
    C --> D["Continue Conversation"]
### Notes - The
DataCollectorAgent
is a generic agent for collecting data, and you can extend it for specific PII capture needs. - Ensure that the PII data handling complies with relevant regulations (e.g., GDPR, HIPAA). - The
session.state
can be used to store temporary data during the conversation, ensuring that context is preserved across agent transitions.```