Need help to trigger events from local storage

Issue Triggering Custom Agent Tool via HTTP Gateway

I am trying to programmatically trigger a custom tool (ingest_document) within a Solace Agent Mesh (SAM) agent (rag_gemini_supabase_agent) from an external Python script. The script watches a local folder and should initiate the ingestion process when a new file appears.

Setup:

  • Solace Agent Mesh project initialized using sam init --gui.

  • Connected to a Solace Cloud broker.

  • Using Google Gemini as the LLM provider.

  • A custom agent (rag_gemini_supabase_agent) was created using sam add agent --gui.

  • This agent has a Python tool defined in tools.py named ingest_document(file_path: str, file_id: str).

  • The Web UI Gateway is enabled and running on the default http://localhost:8000.

  • The ingest_document tool works correctly when invoked via natural language prompts through the Web UI chat (http://localhost:8000).

Problem: An external Python script (file_watcher.py) attempts to trigger the ingest_document tool by sending HTTP requests to the SAM API gateway, but consistently receives a 405 Method Not Allowed error.

Attempts Made: I have tried sending POST requests from the external script using the Python requests library to the following endpoints:

  1. http://localhost:8000/api/request

  2. http://localhost:8000/agent/rag_gemini_supabase_agent_agent/chat

Attempted sending the prompt command (e.g., "ingest the document at '/path/to/file.txt' with the file_id 'file.txt'") using various payload formats:

  • JSON (application/json)

  • Form data (application/x-www-form-urlencoded via the data parameter)

  • Multipart form data (multipart/form-data via the files parameter)

All attempts resulted in a 405 Method Not Allowed response from the server, indicating the POST method is not accepted for these endpoints in the way we are calling them.

Question for Solace: What is the correct method (API endpoint, HTTP verb, payload format, required headers) to programmatically invoke a specific tool (like ingest_document) on a custom agent via the default HTTP/Web UI Gateway provided by sam run? Is there a dedicated API endpoint for this purpose, distinct from the one used by the chat UI?

Hello Gaurav,
Hope you are well. Based on what you have laid out above I believe you are trying to trigger SAM programmatically (Not via the webGUI). There are two ways to do this via REST. The first option is event driven and uses the Solace broker with the Event Mesh Gateway. The second is directly with REST requests which requires the REST Gateway.. For either of these approaches you will not send your REST request directly to the SAM service running at port 8000 on your machine. I recommend the Event Mesh Gateway approach since you are already running a Solace broker. The flow should look like the flow diagram below. You need to send your request to the Solace broker, this event can come into Solace as a REST message, typically on port 943 (https://mr-…:943/api/request) where the broker will convert it to an event or as an event via Solace Messaging (SMF), AMQP or MQTT.
Once the event is β€˜on’ the Solace broker the next step is to get the event to SAM which is where the SAM Event Gateway comes in. You will deploy the Event Gateway and configure the Event Gateway to subscribe to a topic or bind to a queue to handle the event. In the example I provided above the topic is the URI portion of the URL api/request. When you follow the directions for the Event Mesh Gateway you are adding the configuration to your SAM configuration. Once you are finished configuring the gateway it will start when you next issue sam run.

By setting up the SAM Event Mesh Gateway you are enabling SAM to interact with the outside world via events. During initial SAM setup you provided credentials to a Solace broker. SAM is using this broker for internal interactions between agents. You can use the same Solace broker but the process of setting up the Event Mesh Gateway allows SAM to interact with the external world via events.

Please let me know if you have questions or issues.

Thank you,
Jamieson

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Python REQUEST  β”‚
β”‚     Client       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Solace Broker     β”‚
β”‚    (Port 943)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  SAM Event         β”‚
β”‚    Gateway         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Solace Agent      β”‚
β”‚  Mesh              β”‚
β”‚  (Orchestrator)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Agent with        β”‚
β”‚  ingest_document   β”‚
β”‚      tool          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
1 Like