Playbooks
Here you can learn the basics of how to work with playbooks using Python scripts.
What Is a Playbook
Section titled “What Is a Playbook”A Playbook in the Quantly API is a research workflow consisting of sequential prompts that Quantly responds to. Each prompt generates a complete response, incorporating additional context, AI agents, and data from multiple sources, enhancing the context for subsequent steps. Built-in playbooks include:
-
Macro and Micro News Analysis: Analyzes external factors affecting a company via news, covering macroeconomic trends, industry developments, and competitor responses with sentiment analysis and strategic recommendations in structured tables.
-
News Sentiment on Key Competitors: Similar comprehensive analysis focused on competitors.
How to Create a Playbook
Section titled “How to Create a Playbook”Playbooks can be created manually or generated by Quantly.
How to Generate a Playbook
Section titled “How to Generate a Playbook”To request Quantly to generate a Playbook for you you’ll need to provide a title for your new playbook, description of what it should do and detail level:
import requests
api_key = "your_api_key_here"headers = {"Authorization": f"Bearer {api_key}"}base_url = "https://api-v2.quantly-ai.com"
data = { "Title": "Financial Analysis Playbook", "Description": "Analysis of a company's financial performance, focusing on revenue, expenses, and profitability.", "DetailLevel": "Detailed", # Options: "Concise", "Normal", "Detailed"}
response = requests.post(f"{base_url}/v1/playbooks/generate", headers=headers, json=data)
if response.status_code == 200: generated_playbook = response.json()["data"] print(generated_playbook)else: print(f"Error: {response.status_code}\n{response.content}")You can find detailed documentation for this endpoint here.
Note: In response you’ll get a generated model of a playbook that wasn’t yet saved into the system. If you wish to save the generated playbook, you’ll need to use the endpoint from the next section.
How to Create a Playbook Manually
Section titled “How to Create a Playbook Manually”You can define the playbook directly like this:
import requests
api_key = "your_api_key_here"headers = {"Authorization": f"Bearer {api_key}"}base_url = "https://api-v2.quantly-ai.com"
data = { "title": "Custom Playbook", "description": "A custom playbook for specific analysis.", "steps": [ { "title": "Step 1", "prompt": "Analyze revenue trends." }, { "title": "Step 2", "prompt": "Evaluate expense management." }, ],}
response = requests.post(f"{base_url}/v1/playbooks", headers=headers, json=data)
if response.status_code == 200: created_playbook = response.json()["data"] print(created_playbook)else: print(f"Error: {response.status_code}\n{response.content}")You can find detailed documentation for this endpoint here.
Just like with the chat creation, each successful playbook creation returns you an ID that you can retrieve like this:
created_playbook_id = created_playbook['id']Also like with chats, you can search for playbooks.
How to Find a Playbook
Section titled “How to Find a Playbook”Here’s how you can find either your playbooks, or the built-in system ones:
import requests
api_key = "your_api_key_here"headers = {"Authorization": f"Bearer {api_key}"}base_url = "https://api-v2.quantly-ai.com"
params = { "Query": "Custom Playbook", "Type": "User", # Or "System", or omit for all types "Offset": 0, "Limit": 10,}
response = requests.get(f"{base_url}/v1/playbooks/search", headers=headers, params=params)
if response.status_code == 200: playbooks = response.json()["data"] if playbooks: for playbook in playbooks: print(f"Playbook '{playbook['title']}' with ID {playbook['id']}.") else: print("No playbooks found for the given query.")else: print(f"Error: {response.status_code}\n{response.content}")You can find detailed documentation for this endpoint here.
Note: all parameters in this example are optional, omit them to get all your and system playbooks, but don’t forget that you can control the pagination with “Limit” and “Offset”.
How to Run a Playbook
Section titled “How to Run a Playbook”Running a playbook means starting a chat which will execute your selected playbook step by step. If you know the ID of the playbook that you want to run, here’s how you can do it:
import requests
api_key = "your_api_key_here"headers = {"Authorization": f"Bearer {api_key}"}base_url = "https://api-v2.quantly-ai.com"
playbook_id = "01966836-cb6a-7b07-aff5-d465e0457cea" # Earnings Quick Take System Playbook
data = { "CompanyIds": [24937], # Apple's ID "UseInternet": True,}
response = requests.post(f"{base_url}/v1/playbooks/{playbook_id}/run", headers=headers, json=data)
if response.status_code == 200: playbook_chat = response.json()["data"] print(playbook_chat)else: print(f"Error: {response.status_code}\n{response.content}")You can find detailed documentation for this endpoint here.
Note: in this example, all fields in “data” dictionary are optional, but usually playbooks are designed to be applied to different contexts, so most of them need some context to be specified in order to produce meaningful output.
When successfully created, you can get the ID of the new playbook chat like this:
playbook_chat_id = playbook_chat['id']Then you can treat it like a usual existing chat, for which this page might be helpful:
Individual Chats
Here you can learn how to work with simple Chats using Python scripts
Check out the Reference if you need more information about any of these or many other endpoints that we have.