Give your agent files

Add a file with business information for the agent to consult when answering. The example uses your opening hours. Once processed, you can connect the same file to another agent or pause its use.

Before you start

You need an agent (create one) with its id in AGENT_ID.

In the platform: Knowledge.

  1. Create the file, connected to the agent

    Create the file in the workspace and connect it to the agent in the same call. It can be text, a web page or a document.

    import { Platic } from "platic-sdk";
    
    const platic = new Platic({ apiKey: process.env.PLATIC_API_KEY! });
    const agentId = process.env.AGENT_ID!;
    
    // For a web page use createUrl; for a document (up to 50 MiB), createFile.
    const file = await platic.files.createText({
      title: "Opening hours",
      text: "We are open Monday to Friday from 9:00 to 18:00 and on Saturdays from 10:00 to 14:00.",
      attachment: { agentId },
    });

    The response has fileId and uploadId: keep them in FILE_ID and UPLOAD_ID. For a web page or a document, see Create a file.

  2. Wait until it is ready

    Check the processing status. When it finishes, the connection to the agent activates automatically.

    const job = await platic.agents.files.waitForJob(agentId, file.fileId, file.uploadId);
    if (job.status === "failed") {
      throw new Error(job.error?.message ?? "The file could not be processed");
    }

    The file is available to the agent when status: "ready". If it ends as failed, read the reason in error.

  3. Share it with another agent

    The file is already in your workspace: connect it, don't upload it again. (Connect a file)

    const supportAgentId = process.env.SUPPORT_AGENT_ID!;
    
    await platic.agents.files.connect(supportAgentId, file.fileId);

    If you update the file later, it changes for every agent that uses it.

  4. Pause it when it no longer applies

    Pause the file to stop this agent from using it. The connection and file remain; other agents are unaffected.

    await platic.agents.files.setState(agentId, file.fileId, "paused");

    To turn it back on, use active. You can also schedule both changes with a date: see Pause or schedule a file.

Check it worked

Call List the agent's files and check the file's state. Ask the agent about opening hours and compare its reply with the content. Connecting, pausing and disconnecting apply immediately, without publishing the agent.

To take it away from one agent, disconnect it: the file stays in your workspace. To delete it for everyone, delete it.

Next steps