tahutipai0940
# office-hours
t
How does one progmatically attach a File (Knowledge Base) to an agent? (can be transient or persistant agent) -We can programtically Create or Patch agents. -We can progmatically add Files to vapi, and get the FileId, etc But how does one progmatically "attach" a File to an Agent? i.e in the Vapi Dashboard, you can go to your agent, then Knowledge Base, and click and manually add uploaded Files to that agent, very easily. But how does one do that progmatically? Can anyone share the correct API to do this? Can't for the life of me figure it out. @Vapi
v
@Tahutipai To programmatically attach a file from the Knowledge Base to an agent in VAPI, you would typically use the API endpoint that is designed for updating an agent's configuration. Since you mentioned that you can programmatically create or patch agents, you would use the PATCH method to update the existing agent configuration with the FileId of the document you want to attach. Here's a general outline of the steps you would follow: 1. Upload the file to the Knowledge Base and obtain the FileId. 2. Use the PATCH API endpoint for agents, which allows you to update the agent's configuration. 3. In the request body, specify the FileId within the appropriate configuration section that handles Knowledge Base attachments. The exact API endpoint and the structure of the request body can vary based on the specific implementation of VAPI. If this information is not available in the public documentation, you may need to contact VAPI support for the exact details on how to perform this action. If you have the API documentation or can provide more details on the available endpoints, I can give you a more precise answer. Otherwise, please ask support for more info on this.
t
thanks. yes i've tried the PATCH endpoint with the agent, can't figure out how to make it work, api documents seem unclear on this
c
What’s the patch call you’re making?
Typically with patch you just provided the data you want to replace within the item. I’ll take a look when I’m back at my laptop
t
Thanks Chris, id love some help with this, have been trying for well over a dozen hours. I have tried the following by curl commands, and python with the sdk, same results - the agent can never access the KB files. if i add them with the dashboard, it works fine. (I note that, when adding via the dash - no KnowledgeBaseID is added to the agents JSON - but instead, via the dashboard does create a "Knowledgebase" object, which contains the key "topK", and the file ids.... What i have been doing is using the API to upload files, and the using the list of fileIDs, i then use the API to create a KnowledgeBase. This gives me the KBid Then, i patch the agent with the KBID. This never works, then agent can never reference the files. So, my question is: what is the dashboard doing differently from the API? I don't understand why just adding the KB_ID to the agent doesn't work, and i don't understand why, when adding via the Dash, no KB_ID is created. Also, when patching the agent, i dont see any option to "patch" the agent directly with the files. (which makes sense, i guess we want to make a KB first). TLDR: What is the correct process to progrmatically add files/knowledge bases to an agent? The guideline in the vapi documentation doesn't seem to actually work...
c
Are you a kiwi?
t
lol oui, how can you tell??
impressed 🙂
FYI I've also written a python program using the Server SDK that will: -Upload 3 files, get the fileid's -Use those fileid's, and generate a KB_ID -create an OpenAI Model, with the KB_ID -using that openai model, create a new assistant Same problem, same behavior: if i dump the json of the new model, it has a KnowledgeBaseID, but no KnowledgeBase object, and will not respond to any queries regarding the file contents referenced in the KBID in the agent. How do i programmatically replicate the behavior of "manually adding files to the agent in the dashboard"?
FYI I just re-ran through the vapi doc process, from scratch. https://docs.vapi.ai/knowledgebase New agents, new files etc. Confirmed, this process does not work (when following the instructions with curl etc) If it do it with the dashbaord, it does work. The resulting JSON from the agent is quite different, when done via the vapi dash, compared to the vapi docs. Any advice? Even just a nudge in a direction would be most appreciated. Thankyou
so, i found a solution. by avoiding knowledge bases entirely. the vapi docs seem to be very incorrect on this? If i manually patch the agents json as follows, i can get auto adding of documents to work. JSON_DATA=$(cat <<EOF { "model": { "provider": "openai", "model": "gpt-4o", "messages": [ { "role": "system", "content": "$PROMPT_CONTENT" } ], "knowledgeBase": { "topK": 2, "fileIds": [ $FILE_IDS ], "provider": "canonical" } } } EOF )
6 Views