How to call AI agent with python code?

rafael_rosado97
rafael_rosado97 Partner, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 63 Partner

Hello, everybody.

I have already built a visual agent.

I want to build a Dash webapp "calling" that visual agent.

I saw this tutorial, but here tools are in a utils.py file. But I have created my tools as plugins (like mentioned here). I used these tools creating a visual agent.

Is it possible to call my visual agent in a dash webapp?

Thank you.

Operating system used: Ubuntu 22.04

Answers

  • MaximeA
    MaximeA Dataiker, Registered, Product Ideas Manager Posts: 12 Dataiker

    Hello @rafael_rosado97

    An agent in Dataiku is callable with our Python API like any other LLM. So, a very simple snippet would look like the following:

    import dataiku
    
    AGENT_ID = "agent:XXXXXXXX"
    agent = dataiku.api_client().get_default_project().get_llm(AGENT_ID)
    
    # Create and run a completion query
    completion = agent.new_completion()
    completion.with_message(    
        "any message",     
        role="user")
    response = completion.execute()
    

    More information can be found in the Developer Guide here. In the tutorial you are linking, the utils.py file contains a create_chat_session method that uses our API in the same way.

    In order to get the correct AGENT_ID, you need to replace the XXXXXXXX with the 8 characters you'll see in the URL of your visual agent (something like savedmodels/9jkCUzAk/…). Another way is to use the list_llms() method.

    We will try to make it clearer that agents can be used like any LLM with our API.

    Hope this helps !

Setup Info
    Tags
      Help me…