# Function Tooling

This guide shows you how to turn any controllable API endpoint into a **DynamicStructuredTool** in LangchainJS, expanding your AI agent's ability to navigate to a specific page URL.

<pre class="language-typescript"><code class="lang-typescript">import { RunnableConfig } from "@langchain/core/runnables";
import { DynamicStructuredTool } from "@langchain/core/tools";
import { CallbackManagerForToolRun } from "@langchain/core/callbacks/manager";
import { z } from "zod";

const BASE_URL = "https://.ai"

export const ZInput = z.object({
    url: z.string(),
})

export const implementation = (baseUrl:string) => {
    return async (
        input : z.infer&#x3C;typeof ZInput>, 
        runnerManger?:CallbackManagerForToolRun, 
        config?:RunnableConfig
    ) => {
        // Pass sessionID through metadata
        const sessionID = config &#x26;&#x26; config.metadata ? config.metadata.sessionID : ""
        if(!sessionID || sessionID === ""){
            return "Failed because Session ID not provided"
        }
        
        try{
            const response = await axios.post(
                `${BASE_URL}/page/goToPage`, 
                input,
                {
                    headers: {
                        "Authorization": "&#x3C;TOKEN_HERE>"
                        "Content-Type": "application/json"
                    },
                }
            )
            
            return `Navigated to ${input.url} page successfully`
        } catch(error:unknown){
<strong>            if(isAxiosError(error)){ 
</strong><strong>                return `Failed to go to page because: ${error.data.message}`
</strong>            }
            
            return `Failed to go to page because: ${result.error ? result.error.message : "unknown reason"}`
        }
    }
}

// Create a DynamicStructuredTool
export const goToPageTool = new DynamicStructuredTool({
    name: "goToPage",
    description: "Navigates to a specific page url",
    schema: ZInput,
    func: implementation(BASE_URL),
})

// Usage
(async () => {
    // Make sure to create the session first before invoking
    const toolResponse = await goToPageTool.invoke({
        url: "https://google.com"
    },{
        metadata: {
            sessionID: "&#x3C;SESSIOND_ID_HERE>"
        }
    })
    console.log(toolResponse)
})()
</code></pre>


---

# 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://dev-docs.tasknet.co/guides/use-with-ai/function-tooling.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.
