diff --git a/src/Core/src/Chains/StackableChains/Agents/Crew/CrewChain.cs b/src/Core/src/Chains/StackableChains/Agents/Crew/CrewChain.cs index a2a2c66c..aa98ca98 100644 --- a/src/Core/src/Chains/StackableChains/Agents/Crew/CrewChain.cs +++ b/src/Core/src/Chains/StackableChains/Agents/Crew/CrewChain.cs @@ -42,8 +42,17 @@ protected override async Task InternalCall(IChainValues values) task.Tools.Add(new DelegateWorkTool(allAgents.Except(new[] { task.Agent }))); } - var res = await task.ExecuteAsync(Context).ConfigureAwait(false); - Context = res; + string res; + try + { + res = await task.ExecuteAsync(Context).ConfigureAwait(false); + Context = res; + } + catch (Exception ex) + { + Console.WriteLine($"An exception occurred during task execution: {ex.Message}"); + return values; // Return the original values if an exception occurs + } values.Value[outputKey] = res; return values; diff --git a/src/Meta/test/CrewTests.cs b/src/Meta/test/CrewTests.cs index 8ca354b5..90935085 100644 --- a/src/Meta/test/CrewTests.cs +++ b/src/Meta/test/CrewTests.cs @@ -64,12 +64,19 @@ public async Task can_test_crewchain() myAgents.LocalTourGuide }; - var chain = - Set(prompt) - | Crew(agents, myAgents.TravelAgent, inputKey: "text", outputKey: "text") - | LLM(llm); - - Console.WriteLine(await chain.Run("text")); + try + { + var chain = + Set(prompt) + | Crew(agents, myAgents.TravelAgent, inputKey: "text", outputKey: "text") + | LLM(llm); + + Console.WriteLine(await chain.Run("text")); + } + catch (Exception ex) + { + Console.WriteLine($"An exception occurred: {ex.Message}"); + } } [Test]