common-use-cases.mdx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ---
  2. title: "Common Use Cases"
  3. description: "Explore common use cases for custom communication flows in Agency Swarm."
  4. icon: "code"
  5. ---
  6. In the following sections, we'll look at some common use cases for creating custom communication flows and how to implement them in Agency Swarm.
  7. #### 1. Adjusting Parameters and Descriptions
  8. Customize parameters by subclassing `SendMessage` and declaring extra fields directly on the class:
  9. ```python
  10. from pydantic import Field
  11. from agency_swarm import SendMessage
  12. class SendMessageTask(SendMessage):
  13. """Use this tool to send tasks to other agents within your agency."""
  14. tool_name = "send_message_task" # optional, defaults to "send_message"
  15. task: str = Field(
  16. description=(
  17. "Specify the task required for the recipient agent to complete. Focus on "
  18. "clarifying what the task entails rather than providing exact instructions."
  19. )
  20. )
  21. ```
  22. #### 2. Adding Additional Fields
  23. You can add extra fields to capture more context, like key moments and decisions:
  24. ```python
  25. from pydantic import Field
  26. from agency_swarm import SendMessage
  27. class SendMessageWithContext(SendMessage):
  28. """SendMessage with key moments and decisions tracking."""
  29. tool_name = "send_message_with_context"
  30. key_moments: str = Field(
  31. description=(
  32. "Document critical moments and decision points from the current conversation "
  33. "that the recipient agent needs to understand. Include context about what "
  34. "has been decided or prioritized that will guide the recipient's tool selection "
  35. "and task execution. For example: 'User decided to prioritize performance over cost', "
  36. "'Analysis focus shifted to Q4 optimization', etc."
  37. )
  38. )
  39. decisions: str = Field(
  40. description=(
  41. "Summarize the specific decisions made that will directly impact which tools "
  42. "or approaches the recipient agent should use. Be explicit about choices that "
  43. "narrow down the scope of work. For example: 'Prioritized performance analysis "
  44. "over cost reduction', 'Selected React over Vue for frontend', etc. This helps "
  45. "the recipient agent choose the most appropriate tools and approach."
  46. )
  47. )
  48. ```
  49. **Usage:**
  50. ```python
  51. from agency_swarm import Agency, Agent
  52. agent = Agent(
  53. name="MyAgent",
  54. instructions="You are a helpful assistant.",
  55. )
  56. other_agent = Agent(name="OtherAgent", instructions="Provide supporting context.")
  57. agency = Agency(
  58. agent,
  59. other_agent,
  60. communication_flows=[(agent > other_agent, SendMessageWithContext)],
  61. )
  62. ```
  63. <Tip title="Contributing">
  64. If you have any ideas for new communication flows, please either adjust this page in docs, or add your new send
  65. message tool in the `agency_swarm/tools/send_message` folder and open a PR!
  66. </Tip>