> For the complete documentation index, see [llms.txt](https://dev-docs.tasknet.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev-docs.tasknet.co/guides/use-with-ai/function-tooling.md).

# 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>
