8000 Agent Executing Tool endlessly · Issue #1555 · google/adk-python · GitHub
[go: up one dir, main page]

Skip to content
Agent Executing Tool endlessly #1555
Open
@msbarathraj

Description

@msbarathraj

Describe the bug
I'm having a logic to insert json data into database and for some reason the agent is executing it again and again and never ending resulting in multiple duplicate entries in the DB.

Code Below

def create_record(transaction_log: dict) -> str:
    """
    Creates a new record in the TrackerTable with the given transaction_log.
    Returns a simple success message to prevent further processing.
    """
    if not isinstance(transaction_log, dict):
        return "Error: Invalid input format. Expected a dictionary."
    
    print('entering insert tool')
    
    try:
        # Create the data dictionary with all required fields
        data = {
            "transaction_id": str(uuid.uuid4()),
            "created_at": datetime.now().isoformat(), 
            "transaction_amount": transaction_log.get("transaction_amount"),
            "transaction_category": transaction_log.get("transaction_category"),
            "transaction_description": transaction_log.get("transaction_description"),
            "transaction_status": transaction_log.get("transaction_status"),
            "transaction_date": transaction_log.get("transaction_date")
        }
        
        # Insert into database
        supabase.table("TrackerTable").insert(data).execute()
        print('Successfully inserted record')
        return "SUCCESS: Transaction recorded successfully. No further action needed."
    except Exception as e:
        error_msg = f"Error inserting record: {str(e)}"
        print(error_msg)
        return f"ERROR: {error_msg}"

insert_tool = FunctionTool(func=create_record)


database_updater_agent = LlmAgent(
    name="database_updater_agent",
    description="call create_record function through insert_tool to insert the transaction_log into the database.",
    instruction="""
    Use the transaction_log to call create_record via insert_tool.
    After the tool returns a response, show that to the user exactly as-is.
    Do NOT call any other tools again.
    Do NOT repeat or re-enter the function.
    Just return the tool result once and finish.
    """,
    model=LiteLlm(model="ollama/llama3.1:8b"),
    tools=[insert_tool]
)

# Create the root agent
root_agent = SequentialAgent(
    name="transaction_logger_agent",
    sub_agents=[transaction_categorizer_agent, database_updater_agent],
    description="A sequential agent that first categorizes transactions and then updates the database.",
)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0