diff --git a/docs_new/faq.mdx b/docs_new/faq.mdx index ee969692..6cc43695 100644 --- a/docs_new/faq.mdx +++ b/docs_new/faq.mdx @@ -8,28 +8,77 @@ Find answers to common questions about Agency Swarm. - -**A**: Agency Swarm is an open-source framework designed to facilitate the creation and orchestration of multi-agent AI systems. + +**A**: You can implement thread callbacks to save and load thread IDs in a local file. This allows you to maintain conversation context even after interruptions. Here's the basic approach: + +- Create load and save callback functions +- Use these callbacks in your `GenesisAgency` initialization +- Control threads via a `chat_id` parameter - -**A**: Install via pip using: + +**A**: You can use threads callbacks to save thread ids in a local file: + +Create load function: + +```python +def load_threads(chat_id): + if os.path.exists(f"{chat_id}_threads.json"): + with open(f"{chat_id}_threads.json", "r") as file: + return json.load(file) + return [] +``` + +Create save function: -```bash -pip install agency-swarm +```python +def save_threads(new_threads, chat_id): + with open(f"{chat_id}_threads.json", "w") as file: + json.dump(new_threads, file) ``` +Implement in agency: + +```python +agency = GenesisAgency( + with_browsing=False, + threads_callbacks={ + 'load': lambda: load_threads(chat_id=chat_id), + 'save': lambda new_threads: save_threads(new_threads, chat_id=chat_id) + }) +``` +Note: These code examples are simplified for illustration. Production implementations should include proper error handling, security measures, and scalability considerations. - -**A**: Yes, you can integrate open-source models or custom language models that mimic the OpenAI Assistants API. + +**A**: No, for production environments, especially with multiple users or stateless containers, you should: + +- Use a database instead of local file storage +- Implement proper state management +- Consider scalability requirements +- Handle concurrent users appropriately - -**A**: Agents communicate using the `SendMessage` tool, with communication flows defined in the `agency_chart` parameter of the `Agency` class. + +**A**: No, previous messages won't be displayed in the Gradio interface. However, the agents will retain the context of these messages and continue the conversation appropriately. - -**A**: Examples are available in the [agency-swarm-lab](https://github.com/VRSEN/agency-swarm-lab) repository and on the [YouTube channel](https://youtube.com/@vrsen). + +**A**: Here's an example of how to serve an Agency as an API using FastAPI: + +- Define the agency within the chat endpoint: +```python +@app.post("/chat") +async def chat(user_request: UserRequest): + chat_id = user_request.chat_id or str(uuid4()) + agency = Agency([...], + threads_callbacks={ + 'load': lambda: load_threads(chat_id=chat_id), + 'save': lambda new_threads: save_threads(new_threads, chat_id=chat_id) + }) + response = agency.get_completion(user_request.message) + return {"chat_id": chat_id, "response": response} +``` + diff --git a/docs_new/how-to-guides/managing-communication-flows.mdx b/docs_new/how-to-guides/managing-communication-flows.mdx deleted file mode 100644 index 7774a292..00000000 --- a/docs_new/how-to-guides/managing-communication-flows.mdx +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: "Managing Communication Flows" -description: "Learn how to define custom communication flows for your agency." -icon: "comments" ---- - -Effective communication between agents is essential for collaboration. Agency Swarm allows you to define custom communication flows. - -## Defining Communication Flows - -- **Agency Chart**: Communication permissions are set using the `agency_chart` parameter in the `Agency` class. - ```python - agency = Agency([ - ceo, # Entry point for user communication - [ceo, dev], # CEO can communicate with Developer - [dev, va], # Developer can communicate with Virtual Assistant - ]) ``` - -- **Directionality**: Communication is directional, established from left to right. - -## Best Practices - -- **Intentional Design**: Define communication flows that reflect organizational hierarchies or workflows. -- **Limit Unnecessary Access**: Restrict communication paths to prevent information overload or confusion.