# Function call

AIs were limited to answering questions from your static knowledge base.

With function calling, you can have your AI execute a Javascript function that invokes third-party APIs to generate a dynamic answer.

### Creating a function <a href="#creating-a-function" id="creating-a-function"></a>

First, we create a function from the AI Studio -> Function Call screen

<figure><img src="https://633293635-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGQT6bvyjdctMxBrViCPu%2Fuploads%2F1JP6GxeN1EBHNcPxNssv%2Ffunction_call.jpeg?alt=media&#x26;token=bf54c44b-aa72-4d48-8983-232258651b3f" alt=""><figcaption></figcaption></figure>

Each function is made up of 3 things:

#### Prompt <a href="#prompt" id="prompt"></a>

A brief description that helps the AI understand what this function does.

#### Parameters <a href="#parameters" id="parameters"></a>

The list of parameters that are required for this function to be executed. The parameters need to be provided in the form of a JSON array.

#### Function handler <a href="#function-handler" id="function-handler"></a>

This is the Javascript code executed to generate the response to the question asked.

This function would generally consist of

* API endpoint that is to be invoked
* Conditions and logic to ask follow-up questions if parameters are missing

### Testing the function <a href="#testing-the-function" id="testing-the-function"></a>

On the function, click on the 'Save & Run function' to open the test window.

You can customize the LLM model used and see the response generated by it.

Also, to view the exact execution of the function, you can click the 'Show log' to view the entire log.

Here you can view the arguments detected by the function and the output generated by the function.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.swiftsell.biz/ai-studio/function-call.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
