Streamline Your Queries with the ACME Assistant Cognitive Actions

21 Apr 2025
Streamline Your Queries with the ACME Assistant Cognitive Actions

In the ever-evolving landscape of AI, leveraging Cognitive Actions can significantly enhance your application's capabilities. The ACME Assistant, part of the jordillull/acme-assistant spec, provides developers with a simple yet powerful way to integrate natural language processing functionalities into their applications. With the provided actions, you can automate responses to company-related queries, ultimately improving user experience and operational efficiency.

Prerequisites

Before diving into the integration of Cognitive Actions, ensure you have the following:

  • API Key: You'll need an API key to authenticate your requests to the Cognitive Actions platform.
  • Setup: Familiarize yourself with how to send requests, typically involving setting up headers to include your API key for authentication.

Authentication usually involves passing the API key in the headers of your HTTP requests.

Cognitive Actions Overview

Answer Company Query

The Answer Company Query action serves as a basic Q&A assistant, providing answers to common questions related to ACME SL. This action is categorized under natural language processing (NLP) and is designed to simplify the process of retrieving information about the company.

  • Input: The action requires a single input field, prompt, which is a text string that forms the basis for querying information from the system.
    • Input Schema:
    {
      "prompt": "What's the phone number of the company?"
    }
    
  • Example Input:
{
  "prompt": "What's the phone number of the company?"
}
  • Output: The response from this action typically includes a score indicating the confidence level of the answer and the actual answer to the query.
    • Example Output:
{
  "score": 0.629303514957428,
  "answer": "+34 654 321 098 765"
}
  • Conceptual Usage Example (Python):
import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint

action_id = "1ba49f9c-39ef-4bb1-add9-7d047f7b3dda" # Action ID for Answer Company Query

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "What's the phone number of the company?"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload} # Hypothetical structure
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this Python snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID for the "Answer Company Query" is specified, and the input payload is structured according to the required schema. The code is designed to handle potential errors gracefully, ensuring you receive feedback on the execution status.

Conclusion

The ACME Assistant's Cognitive Action for answering company queries provides a straightforward solution for integrating AI-driven responses into your applications. By harnessing these capabilities, you can enhance user interactions and streamline information access. As a next step, consider implementing additional actions or exploring further use cases relevant to your application's needs. Happy coding!