Build FI Dialogue Agents
fi_dialogue_agents is a Python package that simplifies creating dialogue agents using Flask and Socket.IO for FI Dialogue. This wrapper makes it easy to build and deploy agents with minimal configuration, and even allows public access via ngrok reverse tunneling.
Installation
To install the package, simply run:
pip install fi_dialogue_agents
Usagea
Once installed, you can use the Agent class to build your own dialogue agents. Below is a quick guide on initializing agents, handling messages, and running the server.
1. Agent Initialization
The Agent class is the core of this package. Initialize an agent by specifying the host and port for the Flask server:
from fi_dialogue_agents import Agent
# Create an instance of the Agent
agent = Agent(host="0.0.0.0", port=5001)
2. Handling Incoming Messages
You can define a custom message handler using the on_message method. This function is triggered whenever a message is received from the client.
def handle_user_message(message):
print(f"Handling message: {message}")
agent.send_message(f"Echo: {message}")
# Set the custom message handler
agent.on_message(handle_user_message)
3. Running the Server
You can either run the server locally or expose it publicly via ngrok.
a. Running Locally
To start the server locally, use the following command:
agent.run()
b. Running with Ngrok
If you want to expose the server publicly, you can use ngrok. Pass your ngrok authentication token to the run method:
agent.run(debug=True, ngrok_token="<your_ngrok_token>")
You can obtain your ngrok token from ngrok's website.
4. Running the Agent Script
To start the agent, run the following command in your terminal:
python agent.py
This will start the server and, if ngrok is used, provide both the local and public URLs. Hot-reloading is enabled by default, but it is disabled when ngrok is used to prevent generating multiple public URLs.
If you'd like to run the agent as a background process, you can use the nohup command:
nohup python agent.py > output.log 2>&1 &
The server logs, including the ngrok URL, will be saved to output.log.
API Reference
Agent Class
Agent(host, port, cors_allowed_origins): Initializes a new Flask-SocketIO agent.
-
host: The hostname for the Flask server (default: "0.0.0.0"). -
port: The port to run the server (default: 5001). -
on_message(handler): Set a custom handler for user messages.handler: A function that will be called with the incoming message as its argument.
-
send_message(message): Sends a message to the client.message: The message to send back to the client.
-
start_typing(): Sends a typing notification to the client. -
stop_typing(): Stops the typing notification. -
run(debug=True, ngrok_token=None): Starts the Flask-SocketIO server.debug: Whether to run the server in debug mode.ngrok_token: If provided, the server will be exposed to the public via an Ngrok tunnel.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Metadata
Release files for fi-dialogue-agents 0.0.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| fi_dialogue_agents-0.0.11.tar.gz | 8.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fi_dialogue_agents-0.0.11-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.4 kB
Release files / fi_dialogue_agents-0.0.11.tar.gz
| Download URL | fi_dialogue_agents-0.0.11.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
170b83b2a2112008d326134931972634a70593ef791f38bd71932fa088c91dc9
|
|
BLAKE2b-256 checksum How to use checksums |
b37484eb9e7937234fc27f0695b50f36a8f239a8fa506c78f92408bdb8d8156d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|
Release files / fi_dialogue_agents-0.0.11-py3-none-any.whl
| Download URL | fi_dialogue_agents-0.0.11-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e60aa602c6680a55bbac7e239d4d0711c38711bc63e73608270e43658883f352
|
|
BLAKE2b-256 checksum How to use checksums |
f9dfa56c38c5baeaa3ce9e1f2f8d2241f911629bc5c004158fa43f2a83403e71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|
Security for fi-dialogue-agents 0.0.11
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.