Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
A guide to learning a custom BDK Book in Kognitos.
Books must be learned before their procedures can be used in a Playground or Process. Follow the steps below to learn your Book after deployment.
Retrieve the HTTPS endpoint from your deployment.
Place this at the beginning of your automation, substituting your own endpoint in the syntax:
Learn the requirements for deploying a BDK Book.
After successfully building your Book and creating a Docker image, the next step is deployment. You have the flexibility to deploy your Book to any environment that supports external access and routing, ensuring it can be reached from Kognitos. The choice of deployment method will depend on your organization's specific preferences and requirements. Common deployment options include:
On-premises infrastructure
Port Configuration
Ensure that the port specified in the Dockerfile is properly exposed and matches your deployment environment's configuration.
Learn how to set up your Book project with the BDK.
Ensure the following prerequisites are met and dependencies are installed before proceeding.
Set up your project using the BDK Template, a tool designed to simplify the creation of Books.
Enter the following project details or press Enter to keep the defaults:
Navigate into the new project directory. Replace project_slug
with your own Project Slug from the previous step:
We recommend creating a virtual environment to isolate and manage your project dependencies.
2. Create a virtual environment:
3. Activate the virtual environment
Note: To later exit the virtual environment later, run
deactivate
.
4. Install dependencies
Cloud platforms (ex: , )
Container orchestration platforms, such as
Refer to our for additional deployment considerations.
1.
2.
3.
4.
5.
6.
Clone the from GitHub and initialize your project with Cookiecutter:
1. to create the virtual environment inside the project’s root directory:
Run poetry shell
or manually using the following commands:
Project Name
The name of your project.
Sample Book
Project Slug
A URL-friendly version of the project name. If not provided, this will be derived from the project name.
sample_book
Project Description
A short description of the project.
A short description of the project.
Author Name
You or your organization's name.
Kognitos
Initial Version
Initial project version.
0.1.0
An overview of the Book Development Kit (BDK).
Although Kognitos builds and maintains a variety of Books to address common automation use cases, there may be situations where a custom Book is needed. The BDK is designed to help with:
With the BDK, you can create procedures that interact with third-party APIs, databases, and external services. If your organization uses tools or services not natively integrated with Kognitos, you can build a custom Book to integrate them directly into your automation workflows.
Extend Kognitos’ features to support more complex scenarios beyond standard functionality. Whether you need to support advanced data manipulation or custom data validation, the BDK provides the tools to create custom Books that meet your unique requirements.
The BDK is comprised of the following software components:
1
BDK API
The core Python library for Book development.
2
BDK Book Template
3
BDK Linter
4
BDK Poetry Plugin
5
BDK Runtime
A runtime that connects a Book with the Kognitos platform. It is packaged as a Docker image that serves as the foundation for Book containers.
The Book Development Lifecycle outlines the stages of software development for a new Book and how the BDK components interact throughout the process.
The planning phase is where the Book's functionality is defined. In this stage, you identify the external systems the Book will integrate with and outline the workflows or automation goals. This stage clarifies objectives and requirements, setting the foundation for development.
Refer to our Planning Checklist to help you plan your project.
The development phase is where the Book’s functionality is implemented using the BDK API and other tools:
The BDK Book Template provides starter code to streamline setup.
The BDK Linter enforces coding standards and identifies potential issues.
The BDK Poetry Plugin manages dependencies, versioning, and documentation.
The testing phase ensures that Books perform as intended. The BDK Book Template includes a testing framework for validating Book functionality.
In this stage, the Book is packaged and prepared for deployment. The code is packaged with the BDK Runtime using Docker and deployed externally.
Once deployed, the Book is ready to run in Kognitos, enabling you to extend your automations with custom workflows.
Learn how to develop, package, and run your Book locally with the BDK.
Have You Completed the Setup?
Ensure you’ve followed all the steps to set up your BDK project before proceeding. This includes configuring your environment and installing dependencies.
The project is organized with the following structure:
The project root directory is named using the Project Slug (default: sample_book).
📃 book.py
: Contains the core class where your Book is defined and implemented.
📁 data
: Holds images like 🖼️ icon.svg
, the default SVG used as a Book's icon.
📃 test_book.py
: Contains unit tests to validate the Book's functionality.
📃 Dockerfile
: Builds the Docker image.
📃 pyproject.toml
: Manages dependencies and settings.
📃 poetry_scripts.py
: Custom automation script.
📃 poetry.lock
: Locks dependency versions.
📃 README.md
: Project overview documentation, including setup and usage instructions.
📃 USAGE.md
: Reference documentation for your Book. This file is not included by default. For details on how to generate it, see Generating Documentation.
Implement your Book in book.py. This class is auto-generated by the BDK Template and serves as the starting point for your Book’s implementation. Use decorators to configure settings, define procedures, and establish API connections. Refer to the BDK API Reference and example Books for details.
This section outlines essential commands for Book development and testing.
Code formatting automatically adjusts your code's structure, ensuring adherence to coding standards, readability, and maintainability. To apply the formatting, run:
Pylint is used as the source linter for BDK projects. The linter analyzes and enforce coding standards, checks for errors in Python code, and improves code quality. To run the linter:
This command will generate a comprehensive USAGE.md file by extracting and formatting the docstrings from your code. To generate the documentation, run:
Pytest is used to test and validate your book. To run the test suite:
Build a Docker image to package your Book:
Architecture Compatibility
This image pulls the BDK Runtime base image from Docker Hub, which is currently available only for the linux/amd64 architecture. If you're using a machine with a different architecture, you can use the --platform
flag to emulate linux/amd64 when building the image:
To test your Book in Kognitos before deployment, you can run your Docker image locally with ngrok. Ngrok is a tool that creates a secure tunnel to your local machine and provides a public URL to make your local Docker image accessible from the platform.
1. Install ngrok
Follow the installation steps for ngrok based on your system. You will need to sign up for a free account.
2. Obtain your ngrok authtoken
Navigate to Your Authtoken in the ngrok portal and copy your token.
3. Add your authtoken
4. Configure the ngrok api key as an environment variable:
5. Build & run in ngrok mode
This command will invoke a custom script that builds the Docker image and runs it in ngrok mode:
If you are running into issues with `poetry run host`, you can package and run your book manually with the following command:
Make sure to replace auth_token
, project_slug
, and version
with your own values.
6. Copy the URL
You'll see the ngrok address in the following format in the logs. Copy the URL:
7. Add the URL to your automation
Copy the URL and paste it into your Kognitos Playground using this syntax:
If you implemented any custom connections, be sure to connect to your Book after learning it so that you can invoke its procedures.
Understand concepts and how they are utilized in procedures defined by BDK.
Concepts define how data flows in and out of a procedure:
Input concepts represent the inputs that a procedure requires.
Output concepts represent the results that a procedure generates.
Input and output concepts can be defined as either standard or custom types.
The following Python data types can be used to define concepts:
Concepts and parameters are two different entities that are closely related.
Parameters are operated on by Python functions. They are defined in a function's signature and are specific to the function's implementation.
Concepts and parameter names must match to ensure they are properly mapped internally.
Match concepts to parameters by following these guidelines:
Replace spaces with underscores.
Drop possessive constructions ('s).
Don't map articles ('an', 'a', 'the') to parameters; only the nouns they connect should be considered.
Define optional parameters in cases where the input concept is not explicitly defined in the procedure name.
In this example, the concept red car maps to the parameter red_car
. The space is replaced with an underscore.
In the example below:
servicenow's ticket maps to ticket
field maps to field
outlook's standard user maps to standard_user
In this example, the concept ticket maps to the parameter ticket
. The possessive construct ('s) is dropped and the word "field" is ignored.
In the example below, the concept of priority is not explicitly stated in the procedure name. It maps to the optional function parameter, priority
.
In this example:
the city maps to the parameter city
the unit maps to the optional parameter the unit
The output concept, current temperature, is wrapped in parenthesis in the procedure name.
Learn about writing connection commands for Books built with BDK.
Use the following syntax to write a connection command in a Kognitos automation:
{preposition}
– Any preposition that aligns with the plurality of the noun phrase. For example:
Plural noun phrase: via some API keys
Singular noun phrase: via a client credentials method
To pass arguments to your connection, add the with
keyword at the end of the syntax. List each argument on a separately indented line, using the following format:
In this example, api keys is the noun phrase, and several connection arguments are provided.
Learn how to connect with third-party tools and services in your BDK project.
In your connection method docstring, include the following sections in addition to a brief summary:
Specify the Python function's parameters.
When a label is provided in the docstring, the lowercase form is used in a connection command. When not provided, the label will be inferred from the Python variable name.
Example
In this example, API Key
is the label for the api_key
connection argument. The lowercase version of the label is used in a connection command (api key
):
Additional Examples
api_key: ApI kEy
In this example, the connection command uses the lowercase form of ApI kEy
:
api_key: aPi_KeY
In this example, the connection command uses the lowercase version of aPi_KeY
:
No Label
If a label is not provided in the docstring, it is inferred from the Python variable name, api_key
:
The Book Development Kit (BDK) is a software toolkit for developing Books in Kognitos. Books are collections of related automation (tasks). They can be added to an agent to expand automation functionality and integrate with external tools.
A Python template that simplifies the process of developing a new Book.
A linting tool built as a plugin. It analyzes code throughout development to identify potential issues and ensures Books are implemented, documented, and annotated correctly.
A Python dependency management and packaging tool that uses . It manages dependencies, versioning, formatting, and documentation generation for a Book.
Concepts can also be custom types. Custom concepts must be marked with the decorator. Using a is recommended. For example:
Concepts are operated on by Kognitos procedures. Some concepts are included in the name of the decorator.
An internal mapping is created between a Python function and a Kognitos procedure. To ensure a correct mapping, concepts and parameters must .
Consider each connected as a separate parameter. Non-essential noun phrases (e.g., "field," "value") included to clarify context do not require a corresponding parameter.
The @concept
decorator designates a class as a , allowing it to be used as a custom data type for defining procedure inputs and outputs.
*In the case of a List, each element would correspond to a (a noun and its adjectives) in the hierarchy of possessives. For example:
You must first your Book before connecting it.
A connection command is written in Kognitos to instantiate a connection to a third-party tool or service. Whenever a Book implements a using the decorator, a connection command is required in your automation process.
Connection commands are also required when calling a from a BDK Book that requires a connection. Procedures requiring a connection will have connection_required=True
in the decorator.
{book name}
- The name of your Book, as defined in your decorator.
{noun phrase}
– The noun_phrase
defined in your decorator.
Connections enable you to connect to third-party tools and services in your custom Book. To implement a connection, define a Python function in your Book class and decorate it with the decorator. This decorated function serves as the connection handler and defines the syntax for writing a .
You can define multiple connections within a Book, each with its own handler method. Use the noun_phrase
keyword argument in the decorator to assign a unique label to each connection and differentiate between authentication methods.
Define labels for the connection arguments (e.g., API key, credentials) that will be used in your . Labels correspond to parameters in your function's definition.
Text
str
Number
float
, int
Boolean
bool
Bytes
bytes
Date
datetime.datetime
, datetime.date
, datetime.time
File
typing.IO
UUID
uuid.UUID
Table
pyarrow.Table
, arro3.core.Table
, nanoarrow.ArrayStream
Lists
List[str]
, List[int]
Dictionary
Dict[str, Any]
Note:
Any
can be any of the other supported types.
is_a
str
, List[str]
The name of the custom concept to be referred to in the Kognitos platform.*
unset
Any
Specifies a default value to represent an unset state for the concept.
id
str
A unique identifier for the Book.
icon
str
Path to an icon representing the Book. If not provided, a default icon will be used.
name
str
The name of the Book. If not provided, the name will be inferred from the class name.
noun_phrase
str
The book noun phrase.
A checklist to guide the planning of your BDK Book project, covering key requirements and considerations.
Ensure you have access to the following software requirements.
Designing a Book involves defining these procedures to ensure they align with the automation’s objectives. To guide this process, take into account the following considerations:
Identify the specific procedures needed for the Book. Each procedure should have a clear and specific automation purpose.
What actions does the user need to automate in Kognitos?
Can the actions be broken down into individual steps?
Consider these procedures for a Weather Book:
Get the current temperature in a specific city.
Check the current air quality index (AQI).
Determine delays or disruptions caused by severe weather for shipping and transportation.
Notify attendees of weather-related changes for events.
Clearly define each procedure's inputs, outputs, and processing steps.
What input or parameters are needed for each procedure?
What output or data should each procedure return upon completion?
How will data be transformed, manipulated, or processed in each procedure?
Consider an procedure that gets the temperature in a specific city:
Input
City name
Output
Temperature (°F)
Timestamp when the temperature was recorded
Processing Steps
Validate the city name.
Use an API request to get weather data for the specified city.
Parse the response to extract the temperature value and timestamp.
Format the temperature reading to the appropriate unit (Fahrenheit).
Consider common error scenarios and define how they will be handled.
What are the potential error scenarios that could occur?
How will these errors be handled and/or logged?
Consider the following error scenarios for a Weather Book:
1. Invalid Input
A user enters a non-existent city name (e.g., "Atlantis").
The system receives a blank input for the city name.
2. API Unavailability
The weather API is temporarily down or unreachable.
A network timeout occurs during an API call.
If you plan to integrate with an external API in your Book, it’s important to assess the target service's requirements, limitations, and authentication mechanisms. The following considerations will ensure your chosen API aligns with your automation needs and integrates seamlessly into your BDK project.
Understand the authentication requirements for your target integration. BDK supports standard API authentication methods, including API keys, OAuth 2.0, client credentials, etc.
Does the API require authentication? If so, what kind?
Are there specific permissions or roles required to access certain API endpoints?
Can you obtain the necessary access and permissions for all required credentials?
Identify which API endpoints will be used and define the data that will be exchanged.
Which API endpoints will your Book use?
What data will be sent or received?
Review the API’s rate limits and usage quotes. Ensure they can handle your expected request volume and check for additional costs or restrictions.
Are there API rate limits or usage quotes?
Does the API’s rate limit support the expected request volume for your workflows?
Are there additional costs or restrictions for exceeding usage limits?
Evaluate if the API documentation is clear and if provider support is accessible.
Is the API documentation comprehensive and easy to follow?
Does the API provider offer support?
Plan for future scalability and consider how the API will handle growing request needs.
Can the API handle increasing request volumes as workflows grow?
Does the API support additional functionality that might be required in future Books?
Prepare to deploy and manage a Docker container
Ensure the required infrastructure is in place to deploy a Docker container in the cloud, on-premises, or in a hybrid environment.
Plan strategies for:
Managing the container lifecycle, including scaling, networking, and security.
Implementing logging to track container activity
Monitoring container health and performance
Updating Docker images for new releases with clear versioning and testing practices.
Books are collections of procedures that define specific actions within an automation. Each represents an automation task or step contributing to a larger process.
name
str
Optional
Specifies the name of the configuration. If not provided, the function name or value from *args
is used.
default_value
Any
Optional
Specifies the default value for the configuration. If not provided, the default is None
.
id
str
Yes
The unique identifier for the OAuth configuration.
provider
Yes
The OAuth provider:
OAuthProvider.MICROSOFT
OAuthProvider.GOOGLE
flows
List[OAuthFlow]
Optional
A list of OAuth flows.
authorize_endpoint
str
Yes
The authorization endpoint URL for the OAuth provider.
token_endpoint
str
Yes
The token endpoint URL for exchanging the authorization code for a token.
scopes
List[str]
Optional
A list of scopes required by the OAuth provider for the authenticated requests.
The BDK API is the core Python library in the Book Development Kit (BDK). It enables developers to build a Book. This reference covers the essential elements for working with the BDK API.
AND
0
Logical AND operator, used to combine conditions.
OR
1
Logical OR operator, used to combine alternative conditions.
EQUALS
2
Tests if two values are equal.
NOT_EQUALS
3
Tests if two values are not equal.
IN
4
Tests if a value is within a specified list or range.
HAS
5
Tests if a collection contains a specific element.
LESS_THAN
6
Tests if one value is less than another.
GREATER_THAN
7
Tests if one value is greater than another.
LESS_THAN_OR_EQUAL
8
Tests if one value is less than or equal to another.
GREATER_THAN_OR_EQUAL
9
Tests if one value is greater than or equal to another.
Learn about implementing filter expressions in your BDK project.
Filter expressions enable you to define filter criteria for your procedures using the whose keyword. These expressions allow you to filter data based on conditions such as equality, comparisons, and more. For example:
filter_expression
parameterTo implement a filter expression, you need to provide the special filter_expression
parameter in your procedure method definition. For example:
The FilterExpressionVisitor
class is an abstract base class that defines methods for visiting different types of filter expressions. Each type of filter expression (binary, unary, value, noun phrase) is defined as a subclass of FilterExpression
. You will need to define a class that implements these methods to handle filter expressions. For example:
Below is an example implementation of the FilterExpressionVisitor
class in the Twilio Book:
Once you’ve defined your visitor class, you need to pass an instance of it to the filter expression. This is done by calling accept onfilter_expression
. For example:
In this example, a filter expression is used in the read some SMS messages procedure:
Learn about the concept of a noun phrase in the BDK.
A noun phrase is a group of words centered around a noun. It consists of:
Head: The main noun representing the fact.
Modifiers: Optional words providing additional context to the head noun.
The NounPhase
class can be used to represent a noun phrase.
A modifier is an optional part of a noun phrase that provides additional detail about the head noun. It appears before the head and refines the fact being referenced.
In this example:
Head: "dog"
Modifiers: "big", "white"
The resulting noun phrase is "big white dog".
Parameters can be defined as NounPhrase
types to tell the system to use a fact's name instead of its value.
Consider the following procedure method definition, where the city
parameter is defined as a NounPhrase
:
This procedure can be called in an automation where London is a fact with a specific value:
In this example, when London is specified as the city parameter, the system uses the name of the fact (London) instead of its value ("windy").
The @connect
decorator is used to wrap functions that handle connections or authentication tasks. It defines the syntax for writing a connection command, which instantiates the connection in Kognitos to the third-party API or service that's implemented in your Python function.
name
str
A name to associate with the connection. If not provided, it defaults to the function name.
noun_phrase
str
A unique label to identify the authentication method. If not provided, it will be inferred from the function name. Examples include, but are not limited to:
noun_phrase="api keys"
noun_phrase="client credentials"
noun_phrase="user password authentication"
This is an example implementation of connecting to the OpenWeather API using an API key:
Refer to connections for additional context and usage examples.
The @procedure
decorator is used to denote a method within a Book class as a procedure. This links a method to a specific procedure in the Kognitos platform.
1. Naming Conventions
Names must begin with to. This defines the action or intent of the procedure. For example:
@procedure("to capitalize a (string)"
@procedure("to get the (current temperature)")
@procedure("to send an *SMS* message")
2. Output Concepts
Output concepts are wrapped in parentheses ()
. For example:
3. Proper Nouns
Proper nouns are wrapped between asterisks **
. For example:
In this example, office365
is considered a proper noun. The procedure is referred to as 'get some users from office365' rather than the office365
.
name
str
Yes
connection_required
bool
A boolean that indicates whether a connection to the service is required to execute the procedure. If not specified, it defaults to None
.
noun_phrase
str
A string that represents the noun phrase for the procedure.
This method implements a procedure that capitalizes a string with one input concept and one output concept.
This method implements a procedure that creates an order in Truckmate. It has one input concept and two output concepts.
The following method implements a procedure that reads SMS messages using the Twilio API. In this example, SMS
is a proper noun.
Understand how to format and write docstrings to ensure your Book is well-documented.
Docstrings are placed immediately after function, class, or method definitions.
A brief summary that describes the functionality begins the docstring.
The summary is followed by organized sections, separated by blank lines and labeled with headers.
In BDK projects, docstrings are applied to decorated methods and classes.
The following sections are supported in BDK docstrings, with alternative headers available for labeling flexibility.
Documents the arguments or parameters that a function or class accepts.
Supported Headers: Args
, Arguments
, Parameters
, Params
Example
Documents the return value of a function or method.
Supported Headers: Returns
Example
Lists any exceptions or errors that a function might raise.
Supported Headers: Raises
, Exceptions
, Except
Example
List instance attributes in a class.
Supported Headers: Attributes
Example
Attributes the author(s) of the code.
Supported Headers: Author
Example
Supported Headers: Labels
Example
Supported Headers: OAuth Labels
Example
Supported Headers: OAuth Arguments
Example
Supported Headers: Input Concepts
Example
Supported Headers: Output Concepts
Example
Outlines usage examples for a procedure.
Supported Headers: Example
, Examples
, Example [1-5]
Example
A description that reflects the action or purpose of the procedure. See the syntax for details.
BDK docstrings adhere to formatting:
Defines labeled data associated with a function related to .
Describes OAuth labels for classes decorated with the .
Describes OAuth arguments for classes decorated with the .
Describes the for a procedure.
Describes the for a procedure.
Learn how to implement a procedure with the BDK.
To implement a procedure in a BDK project, define a Python function in your Book class and decorate it with the @procedure decorator.
Ensure the name of your procedure adheres to the syntax guidelines specified in the name
parameter of the @procedure decorator.
Your method docstring should include the following sections:
A brief summary of the procedure
Input Concepts
Output Concepts
Examples are not required but are valuable for generating usage documentation.
Concepts and parameters must match to ensure they are properly mapped internally. Ensure your method definition adheres to the guidelines.
A singularized call is a way to call a procedure by phrasing it as if it returns a single item, even though it returns a list by definition. A procedure supports singularized calls in addition to standard calls if it meets all of the following conditions:
Returns a list.
The output of the procedure is the object itself.
The output noun phrase is plural.
The procedure accepts filters.
You don't need to implement additional logic for singular calls. BDK will automatically generate the singularized variation of any procedure that meets the above criteria.
Consider a procedure that retrieves users from Outlook. It can be called in two ways:
Standard Way: get some users from outlook whose whose mail is "example.com"
Singularized Way: get a user from outlook whose whose mail is "example.com"