Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance log storage to support more data types #1530

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

MottoX
Copy link
Contributor

@MottoX MottoX commented Oct 29, 2024

Problem

Our team is using crewAI for financial applications where non-basic data types like date, datetime and Decimal are heavily used. Input data to the crew contains such non-basic types which are usually retrieved from upstreaming data source.

After upgrading crewAI, the code execution failed because such data types in crew inputs are not handled during log storage inside crewAI. This has been a blocking issue for us and we would like to propose change to solve this and enhance the log storage.

Proposed Change

Manage encoding for different data types in CrewJSONEncoder and use CrewJSONEncoder when seralizing the crew inputs during log storage.

Test Case

The following sample code fails due to errors like TypeError: Object of type {type} is not JSON serializable where type in the error message can be date, datetime, Decimal, etc. After applying the proposed change, the crew inputs can be successfully encoded and saved as defined and managed in CrewJSONEncoder.

from datetime import date
from decimal import Decimal

from crewai import Agent, Task
from crewai import Crew, Process


salesperson = Agent(
    role='Salesperson',
    goal='Describe the products to the customer',
    verbose=True,
    llm="gpt-4o-mini",
    backstory="A salesperson who recommends and sells product to customers"
)

introduce_product = Task(
    description='Given the product name: {name}, begin date: {begin_date} and total funds {total_funds}, '
                'write a short introduction to the product',
    expected_output="Several sentences",
    async_execution=False,
    agent=salesperson
)

crew = Crew(
    agents=[salesperson],
    tasks=[introduce_product],
    process=Process.sequential
)

product_data = {
    'name': 'product A',
    'total_funds': Decimal("123456789.12"),
    'begin_date': date(2023, 1, 1)
}

crew.kickoff(inputs=product_data)

@bhancockio bhancockio self-assigned this Oct 30, 2024
@bhancockio bhancockio merged commit 4ae0746 into crewAIInc:main Oct 30, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants